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 72 73 74 75 76 77 78 79 80
| SMTPPort = ini->ReadString("Configuration","SMTPPort", "");
SMTP->AuthType = 1;
SMTP->Username = Login; // "adr@gmail.com";//ajout login
SMTP->Password = Passwd; //
SMTP->Host = ServerSMTP; // "smtp.gmail.com"; //adresse de l'hote
SMTP->Port = SMTPPort.ToInt(); // port SMTP
SSLMethod = ini->ReadString("Configuration","SSLMethod", "");
SSLOption = ini->ReadString("Configuration","SSLOption", "");
TIdSSLIOHandlerSocketOpenSSL* ioHandler =new TIdSSLIOHandlerSocketOpenSSL(Form1);
SMTP->IOHandler = ioHandler;
SMTP->UseTLS = utUseImplicitTLS;
SMTP->AuthType = satDefault;
// SMTP->Authenticate();
// sécurité en plus pour gmail
//TIdSSLIOHandlerSocketOpenSSL* ioHandler =new TIdSSLIOHandlerSocketOpenSSL(NULL);
ioHandler->SSLOptions->Mode = sslmClient;
ioHandler->SSLOptions->VerifyDepth = 0;
if(SSLOption=="sslvSSLv2")
ioHandler->SSLOptions->SSLVersions << sslvSSLv2 ; // sslvSSLv2, sslvSSLv23, sslvSSLv3, sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2
else if(SSLOption=="sslvSSLv23")
ioHandler->SSLOptions->SSLVersions << sslvSSLv23 ;
else if(SSLOption=="sslvSSLv3")
ioHandler->SSLOptions->SSLVersions << sslvSSLv3 ;
else if(SSLOption=="sslvTLSv1")
ioHandler->SSLOptions->SSLVersions << sslvTLSv1 ;
else if(SSLOption=="sslvTLSv1_1")
ioHandler->SSLOptions->SSLVersions << sslvTLSv1_1 ;
else if(SSLOption=="sslvTLSv1_2")
ioHandler->SSLOptions->SSLVersions << sslvTLSv1_2 ;
//ioHandler->SSLOptions->VerifyMode = TIdSSLVerifyModeSet();
if(SSLMethod=="sslvSSLv2")
ioHandler->SSLOptions->Method =sslvSSLv2 ;// sslvSSLv2, sslvSSLv23, sslvSSLv3, sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2
else if(SSLMethod=="sslvSSLv23")
ioHandler->SSLOptions->Method<< sslvSSLv23 ;
else if(SSLMethod=="sslvSSLv3")
ioHandler->SSLOptions->Method << sslvSSLv3 ;
else if(SSLMethod=="sslvTLSv1")
ioHandler->SSLOptions->Method << sslvTLSv1 ;
else if(SSLMethod==u"sslvTLSv1_1")
//ioHandler->SSLOptions->Method << sslvTLSv1_1 ;
/* else if(SSLMethod=="sslvTLSv1_2")
ioHandler->SSLOptions->Method << sslvTLSv1_2 ;*/
//ioHandler->SSLOptions->Method = sslvSSLv23 ;
ioHandler->PassThrough = false;
SMTP->IOHandler = ioHandler;
SMTP->UseTLS =1;
SMTP->UseTLS = utUseExplicitTLS; // a decom
// rajouté
SMTP->AuthType = satDefault;
SMTP->IOHandler = ioHandler;
//SMTP->UseTLS = utUseImplicitTLS; // il f le comme
ioHandler->DefaultPort = 443;
//ioHandler->SSLOptions->Method = sslvSSLv3 ; //3 //587
ioHandler->SSLOptions->Mode = sslmClient;
try
{
SMTP->UseEhlo = True;
SMTP->UseVerp = False;
SMTP->ReadTimeout = 100000;
SMTP->Connect();
SMTP->Authenticate();
SMTP->Send(Message);
}
catch (Exception &e)
{
ShowMessage("problème d'envoi de mail : " + e.Message);
}
SMTP->Disconnect(true);
delete ptrAttachmentFile;
delete Message;
delete SMTP;
delete ini;
delete ioHandler ; |
Partager