0

I'm testing out a simple script to send an Outlook email from Python 3 (using Spyder).

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

username = 'my_username@my_company.com'
password = 'my_password'

mail_from = username
mail_to = username
mail_subject = "Test Subject"
mail_body = "This is a test message"

mimemsg = MIMEMultipart()
mimemsg['From']=mail_from
mimemsg['To']=mail_to
mimemsg['Subject']=mail_subject
mimemsg.attach(MIMEText(mail_body, 'plain'))

try:
    connection = smtplib.SMTP(host='smtp.office365.com', port=587)
    connection.starttls()
    connection.login(username,password)
except Exception as e:
    print('Got error here')
    print(e)

And the output is:

Got error here
(535, b'Authentication unsuccessful, the user credentials were incorrect. [SOME_VALUE_HERE.hostname.prod.outlook.com]')

I know for sure my own username and email are correct - I verified by checking my username's properties > SMTP value. And anyway it's the username I use to login to Windows.

I'm also using the same password for logging into Windows.

Is it possible my company uses different values for host or port? Or on the backend it sends a different user name to the SMTP server?

1 Answer 1

1

The error indicates that SMTP authentication is disabled. Read more about that on the page at https://aka.ms/smtp_auth_disabled. The link explains how to enable SMTP AUTH for the whole organization or only for some mailboxes.

Also take a look at the following settings that would block Legacy Authentication:

settings that block Legacy Authentication in outlook

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.