Bonjour
Je voudrais envoyer un mail avec les composants Indy.
J'ai ajouté à la form les composants idsmptp et idmessage
puis j'ai utilisé le code suivant trouvé sur le net :
Par souci de test, j'ai forcé les variables selon mes données personnelles. J'ai coupé l'antivirus/firewall pour éviter de poser problème avec les ports.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 function send_mail():Boolean; var FileName : String; begin try Result := False; //FileName := 'myfile.txt'; //Setup SMTP Form1.IdSMTP1 := Form1.IdSMTP1.Create(nil); Form1.IdSMTP1.Host := 'smtp.live.com'; Form1.IdSMTP1.Port := 587; //Default email port Form1.IdSMTP1.Username := 'mon_mail@hotmail.fr'; // SMTP user name Form1.IdSMTP1.Password := 'secret'; // Form1.IdMEssage1.From.Address := 'mon_mail@hotmail.fr'; Form1.IdMEssage1.Recipients.EMailAddresses := 'mon_mail@hotmail.fr'; Form1.IdMEssage1.Subject := 'Test Email from Delphi XE2'; Form1.IdMEssage1.Body.Text := 'Hi! This is test email from delphi XE2'; //Attach a file //if FileExists(FileName) then TIdAttachmentFile.Create(MailMessage.MessageParts, FileName); //Send email try try Form1.IdSMTP1.Connect; Form1.IdSMTP1.Send(Form1.IdMEssage1); Result := True; except on E:Exception do begin ShowMessage('Cannot send E-Mail: ' + E.Message); Result := False; end; end; finally if Form1.IdSMTP1.Connected then Form1.IdSMTP1.Disconnect; end; except on E : Exception do begin ShowMessage('Error in the function SendEmailDelphi: ' + E.Message); Result := False; end; end; end;
"smtp.live.com" est lié à hotmail.com
le port 587 aussi.
A l'exécution, j'ai ce bug :
Project1.exe raised exception class EIdSMTPReplyError with message ''.
Quelqu'un a une idée?
Partager