SMPT with Outlook.com & two factor authentication

hello everyone here’s how to configure the sending of SMTP mail with outlook.com

configuration.yaml :

notify:
  - platform: smtp
    name: smtpmail
    server: smtp.office365.com
    port: 587
    timeout: 15
    sender: !secret notification_sender
    starttls: true
    username: !secret notification_username
    password: !secret notification_password
    recipient:
      - !secret notification_recipient
    sender_name: My Home Assistant

and in secrets.yaml

notification_sender: YOURMAIL
notification_username: YOURMAIL
notification_password: YOURPASSWORD
notification_recipient: YOURMAIL

To create a new app password for an app or device, take the following steps. You can repeat these steps to create an app password for as many apps or devices as you need.

  1. Go to the Security basics page and sign in to your Microsoft account.
  2. Select More security options .
  3. Under App passwords , select Create a new app password . A new app password is generated and appears on your screen.
  4. Enter this app password where you would enter your normal Microsoft account password in YOURPASSWORD.
7 Likes

For me it doens’t work. I get this error:

smtplib.SMTPAuthenticationError: (535, b’5.7.139 Authentication unsuccessful, basic authentication is disabled. [VI1P194CA0042.EURP194.PROD.OUTLOOK.COM 2024-10-07T12:00:20.363Z 08DCE68926E4D029]')

2024-10-07 15:00:20.380 ERROR (MainThread) [homeassistant.components.notify] Failed to initialize notification service smtp