2

I am running a python code for sending an email from my Hotmail account. The code I am using is:

def initmail():
    signin()
    ##if "gmail" in username:
    ##    server = smtplib.SMTP('smtp.gmail.com', 587)
    ##if "hotmail" in username:
    server = smtplib.SMTP('smtp.live.com', 587)
    server.starttls()
    server.login(username, password)
    messenger()
    msg = MIMEMultipart()
    msg['From'] = username
    msg['To'] = mailto
    msg['Subject'] = subject

    body = bodytext
    msg.attach(MIMEText(body, 'plain'))

    text = msg.as_string()
    server.sendmail(username, mailto, text)
    server.quit()

user enters the email address and password in signin function. But I get the following error:

enter image description here

Why is the code generating this error?

  • This means that the email server isn't allowing you access. You need to go into the settings on the email account and allow SMTP access from other applications. There are plenty of instructions for doing it for Gmail but I am struggling to find this option for Outlook365 – mjp Feb 02 '17 at 15:08

0 Answers0