how to send an email from my regular outlook account using smtplib in python

373 Views Asked by At

Im trying to send an email from my regular outlook (or other email server) account in python using the smtplib.However I can only find help on sending from my localhost. Could anyone help me with this?

i have tried many suggestions online but none seem to work.

1

There are 1 best solutions below

0
yoni halbe On

hey for anyone who this may help i managed to find a solution to the problem, although i dont fully understand the code.

import smtplib

username='[email protected]'
password='******'
mailServer = smtplib.SMTP('smtp-mail.outlook.com', 587)
mailServer.login(username, password)
msg = """
Hello!"""
mailServer.sendmail("[email protected]", 
"[email protected]", msg)

hope this helps anyone with the same problem!

ps: if anyone could explain the followings lines of code to me would be great:

mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()

thx!