delphi - Using INDY 10 SMTP with Office365 -
i'm not familar indy smtp component. want send mail indy , office 365. here nice topic helped me lot: what smtp indy component security , authentication properties do? did not figured out how use sasl. office365 adress smtp.office365.com port 587 , tls. added smtp , openssl-iohandler form , setted properties. didn't work, app freezing. need know how use sasl office365.
thanks.
office365 supports login sasl on tls port 587.
the following code works fine me when tried (all of these settings can set @ design-time well):
setting
tidsmtp.authtypepropertysatdefault, uses smtpauth logincommand:var idsmtp1: tidsmtp; begin idsmtp1 := tidsmtp.create(nil); try idsmtp1.iohandler := tidssliohandlersocketopenssl.create(idsmtp1); idsmtp1.usetls := utuseexplicittls; tidssliohandlersocketopenssl(idsmtp1.iohandler).ssloptions.method := sslvsslv3; idsmtp1.host := 'smtp.office365.com'; idsmtp1.port := 587; idsmtp1.authtype := satdefault; idsmtp1.username := ...; idsmtp1.password := ...; try idsmtp1.connect; try idsmtp1.authenticate; idsmtp1.disconnect; end; showmessage('ok'); except on e: exception begin showmessage(format('failed!'#13'[%s] %s', [e.classname, e.message])); raise; end; end; idsmtp1.free; end;setting
tidsmtp.authtypepropertysatsasl, usingtidsasllogin, uses same smtpauth logincommand:var idsmtp1: tidsmtp; idsasllogin: tidsasllogin; iduserpassprovider: tiduserpassprovider; begin idsmtp1 := tidsmtp.create(nil); try idsmtp1.iohandler := tidssliohandlersocketopenssl.create(idsmtp1); idsmtp1.usetls := utuseexplicittls; tidssliohandlersocketopenssl(idsmtp1.iohandler).ssloptions.method := sslvsslv3; idsmtp1.host := 'smtp.office365.com'; idsmtp1.port := 587; idsasllogin := tidsasllogin.create(idsmtp1); iduserpassprovider := tiduserpassprovider.create(idsasllogin); idsasllogin.userpassprovider := iduserpassprovider; iduserpassprovider.username := ...; iduserpassprovider.password := ...; idsmtp1.authtype := satsasl; idsmtp1.saslmechanisms.add.sasl := idsasllogin; try idsmtp1.connect; try idsmtp1.authenticate; idsmtp1.disconnect; end; showmessage('ok'); except on e: exception begin showmessage(format('failed!'#13'[%s] %s', [e.classname, e.message])); raise; end; end; idsmtp1.free; end;
update: office365 no longer supports ssl v3, must use tls v1.x now:
(idsmtp1.iohandler).ssloptions.method := sslvtlsv1;
Comments
Post a Comment