Send Email via Outlook and SMTP

Microsoft's email service, Outlook (formerly Hotmail), allows application developers to send emails through the SMTP protocol. This is what you need to know about Outlook's SMTP server:

  • Domain:

  • Port: 587

  • Security protocol: TLS

With this information and the help of the standard email and smtplib modules, we can use the following code to send an email from an Outlook account (it also accepts the old,, etc.):

from email.message import EmailMessage
import smtplib
sender = ""
recipient = ""
message = "Hello world!"
email = EmailMessage()
email["From"] = sender
email["To"] = recipient
email["Subject"] = "Test Email"
smtp = smtplib.SMTP("", port=587)
smtp.login(sender, "my_outlook_password_123")
smtp.sendmail(sender, recipient, email.as_string())

You'll need to replace "" and "my_outlook_password_123" with the credentials of the Outlook account which you want to send the email from.

For a general explanation of the structure of this code and how to include HTML code and/or file attachments, see our post on the email and smtplib modules: Send HTML Email With Attachments via SMTP.