SMTP Implicit TLS and Explicit TLS using Indy 10.6.2.5341 in Delphi -


a bit of odd 1 here, when setting "usetls" utuseexplicittls , connecting mail server on implicit tls port, first attempt allows connection , sends email, subsequent attempts on port correctly fail.

just wondering if has ideas on how avoid false positive on initial connect , send.

the check handle non-standard ports may getting used user's mail server. pretty examples i've seen assume correct information provided.

below code portion handles (excluding error logging):

function sendtestemail(emailaddress: string): boolean; var   emailmessage: tidmessage; begin   idsmtpemail.authtype := satdefault   idsmtpemail.username := ...;   idsmtpemail.password := ...;   idsmtpemail.port := 465;    idsmtpemail.iohandler := tidssliohandlersocketopenssl.create(idsmtpemail);   idsmtpemail.usetls := utuseexplicittls;   tidssliohandlersocketopenssl(idsmtpemail.iohandler).ssloptions.method := sslvtlsv1_2;   try     // connect     idsmtpemail.connect('smtp.gmail.com');      try       // create       emailmessage := tidmessage.create(nil);        try         // set values         emailmessage.body.add('test email');         emailmessage.subject := 'test email';          // set sender details         emailmessage.from.address := 'test@test.com';         emailmessage.from.name := 'ssl test';          // set recipient         emailmessage.recipients.add.address := emailaddress;          try           // send message           idsmtpemail.send(emailmessage);          except           // exception           on e: eidsmtpreplyerror           begin             // result             result := false;           end;         end;                // free email         emailmessage.free;       end;            // disconnect       idsmtpemail.disconnect;     end;    except     // exception     on e: exception     begin       idsmtpemail.disconnect;       // result       result := false;     end;   end; end; 

using below code, correctly failed on attempts of trying email port 465.

i don't pretend understand why works original didn't.

function sendtestemail(emailaddress: string): boolean; var   emailmessage: tidmessage;   idsslhandler: tidssliohandlersocketopenssl; begin   idsmtpemail.authtype := satdefault;    idsslhandler := tidssliohandlersocketopenssl.create;   idsslhandler.ssloptions.method := sslvtlsv1_2;    idsmtpemail.iohandler := idsslhandler;   idsmtpemail.usetls := utuseexplicittls;    idsmtpemail.username := ...;   idsmtpemail.password := ...;   idsmtpemail.port := 465;    try     // connect     idsmtpemail.connect('smtp.gmail.com');      try       // create       emailmessage := tidmessage.create(nil);        try         // set values         emailmessage.body.add('test email');         emailmessage.subject := 'test email';          // set sender details         emailmessage.from.address := 'test@test.com';         emailmessage.from.name := 'ssl test';          // set recipient         emailmessage.recipients.add.address := emailaddress;          try           // send message           idsmtpemail.send(emailmessage);          except           // exception           on e: eidsmtpreplyerror           begin             // result             result := false;           end;         end;                // free email         emailmessage.free;       end;            // disconnect       idsmtpemail.disconnect;     end;    except     // exception     on e: exception     begin       idsmtpemail.disconnect;       // result       result := false;     end;   end; end; 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -