I have this python program that sends me daily emails. This is my personal email account with Microsoft outlook.com. My code has been working fine but broke yesterday. Here is my code
def email(subject, text):
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
user = "xxx@hotmail.com"
passwd = "xxxxxx"
sender = 'xxx@hotmail.com'
receiver = 'xxx@hotmail.com'
msg = MIMEMultipart('mixed')
msg['Subject'] = subject
msg['From'] = 'xxx@hotmail.com'
msg['To'] = 'xxx@hotmail.com'
text_plain = MIMEText(text,'plain','utf-8')
msg.attach(text_plain)
server = smtplib.SMTP('smtp.office365.com', 587)
server.ehlo()
server.starttls()
server.login(user, passwd)
server.sendmail(sender, receiver, msg.as_string())
server.quit()
User, sender, receiver, to and from are all the same email address. When I run the script, I got this error
>>> email('test subject', 'test message')
File "<stdin>", line 1, in <module>
File "<stdin>", line 19, in email
File "/usr/lib/python3.6/smtplib.py", line 730, in login
raise last_exception
File "/usr/lib/python3.6/smtplib.py", line 721, in login
initial_response_ok=initial_response_ok)
File "/usr/lib/python3.6/smtplib.py", line 642, in auth
raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b'5.7.3 Authentication unsuccessful [MW4PR03CA0229.namprd03.prod.outlook.com]')
Any ideas what could go wrong? This script has been working for at least half year.. Thanks! Difan