3

I can send emails via a Gmail account using the Yagmail module in Python but I am getting a SMTPAuthenticationError when I try to do it with an Outlook email address.

Gmail required me to allow "less secure apps" to access my account but I can't find any such option for Outlook365.

This is my code for Gmail with Yagmail:

import keyring
keyring.set_password('yagmail', '[email protected]', 'mypassword')

import yagmail
FROM = "[email protected]"
TO = "[email protected]"
SUBJECT = "test email"
TEXT = "details go here"

yagmail.SMTP(FROM).send(TO, SUBJECT, TEXT)
mjp
  • 1,618
  • 2
  • 22
  • 37

1 Answers1

4

I got it to work using the following:

import yagmail
FROM = '[email protected]'
TO = '[email protected]'
SUBJECT = 'test email'
TEXT = 'details go here'

yag = yagmail.SMTP('myO365email.com', 'myO365pw', host='smtp.office365.com', port=587, smtp_starttls=True, smtp_ssl=False)
yag.send(TO, SUBJECT, TEXT)

The trick was to configure the SMTP TLS/SSL options.

dnlbrky
  • 9,396
  • 2
  • 51
  • 64