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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| procedure Tfm_ActivexMEDIC.btn1Click(Sender: TObject);
var
idSmtp : TidSmtp;
IdMessage : TIdMessage;
msg : string;
useTLS : Boolean;
SSLHandler: TIdSSLIOHandlerSocketOpenSSL;
begin
useTLS := chk1.Checked;
Screen.Cursor:=crHourGlass;
SSLHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
with SSLHandler do
begin
Destination :='smtp.gmail.com:465';
Host := 'smtp.gmail.com';
MaxLineAction := maException;
Port := StrToInt(cbb1.Text);
SSLOptions.Method :=sslvTLSv1;
SSLOptions.Mode := sslmUnassigned;//sslmClient ;//
SSLOptions.VerifyMode := [];//[sslvrfClientOnce];
SSLOptions.VerifyDepth := 0;
end;
idSmtp := TIdSMTP.Create(nil);
with idSmtp do
begin
IOHandler := SSlHandler;
UseTLS := utUseImplicitTLS;
AuthType := satDefault;
HeloName := 'smtp.gmail.com';
Host := 'smtp.gmail.com';
Port := StrToInt(cbb1.Text);
UserName := 'monmail@gmail.com'; //Nom d'utilisateur
Password := 'monMDP'; //Mot de passe
end;
if useTLS then
begin
idSMTP.IOHandler := SSLHandler;
idSMTP.UseTLS := utUseImplicitTLS; // 1
end
else begin
idSMTP.UseTLS:=utNoTLSSupport; // 0
end;
//// Envoi Smtp
IdMessage := TIdMessage.Create(IdSMTP);
IdMessage.Clear; //Efface l'entête et le corps du message
IdMessage.From.Text :='monmail@gmail.com'; //Adresse email de l'expediteur
IdMessage.ReplyTo.EMailAddresses:= 'monmail@gmail.com'; //Adresse email où le destinataire pourra répondre
IdMessage.Recipients.EMailAddresses:='monmail@gmail.com'; //Adresse email du destinataire
idMessage.ContentType := 'multipart/mixed';
try
idSmtp.AuthType := satNone; //1
idSMTP.Connect;
idSMTP.Send(idMessage);
idSMTP.Disconnect;
msg := 'SMTP Ok, le message a été envoyé à l''adresse indiquée';
MessageBox(0, Pchar(msg), 'Confirmation', MB_ICONINFORMATION or MB_OK);
except
on e : Exception do
begin
Screen.Cursor:=crdefault;
msg:='Impossible de se connecter au serveur SMTP' + sLineBreak + e.Message;
MessageBox(0,Pchar(msg), 'Erreur', MB_ICONERROR or MB_OK);
end;
end;
Screen.Cursor:=crdefault;
end; |