Search code examples
delphiindydelphi-2007indy10

Sending emails with Outlook.com using Indy


In the past i could send emails successfully with Indy and Hotmail, but when i try to send using an Outlook account, i always get the 'Authentication unsuccessful' error. My username and password are correct, i can logon on Outlook.com webmail.

Here is my code :

idsmtp1.Host := 'smtp.outlook.com';
idsmtp1.port := 587;
idsmtp1.Username := '[email protected]';
idsmtp1.Password := 'mypassword';
idsmtp1.IOHandler := IdSSLIOHandlerSocketOpenSSL1;
idsmtp1.usetls := utUseExplicitTLS;
idsmtp1.UseEhlo := true   ;

IdSSLIOHandlerSocketOpenSSL1.SSLOptions.Method := sslvTLSv1;
IdSSLIOHandlerSocketOpenSSL1.SSLOptions.Mode := sslmClient;

idsmtp1.connect;
idsmtp1.Send(idmessage1);

Solution

  • If you've made zero changes to your code, and it decided to stop working, then there is an authentication issue with your Outlook.com account.

    It's most likely that you need to enable 2-step verification and create an application password. Email services typically block you from using your standard password unless the app supports more modern login methods, and they force you to set up applications on your account to access it. You'll have to enable 2-step verification first before you can access the app passwords section.

    enter image description here

    These can be located at Outlook.com > Options > Account Details > Security & Privacy > More Security Settings