Search code examples
delphiindy10

Indy SMTP for hotmail with app password and two step verification


Since some days Indy TIdSMTP can no longer send email from my program from a Hotmail account throwing the error Authentication unsuccessful Basic authentication is disabled.

I activated two-step verification and generated an app password replacing the old password in code without changing any other setting used before but the same error.

I use smtp-mail.outlook.com/587 for host/port config and the following code :

  SMTP.Username := cbxFrom.Text;
  SMTP.Password := pwd;
  SMTP.Host := 'smtp-mail.outlook.com';
  SMTP.Port := 587;
  SMTP.Connect;

It fails on :

  SMTP.Send(msg);

Same problem with TIdImap4.

Any example of how to send or receive to/from Hotmail using two-step and app password?


Solution

  • As of September 16th 2024, you have to now use OAuth2 authentication with Microsoft.

    Modern Authentication Methods now needed to continue syncing Outlook Email in non-Microsoft email apps

    You can take a look at Geoff Smith's code which uses SMTP with XOAUTH2:

    https://github.com/geoffsmith82/GmailAuthSMTP

    It means that it can be integrated with existing Indy code, but yeah.. there are also REST APIs.