Work Automation – email send out via Python (Outlook Servers)

This project has been done before on this site, the only difference here is we’ll be making use of Outlook servers

In this script we make use of the Python SMTP library which defines an SMTP client session object that can be used to send mail. The Outlook server we will be accessing can be defined as:

Find the full source code for this project below. Note that unlike Gmail, Outlook does not require any relaxing of permissions to allow for third party applications to send emails and so there are no prerequisites to this project.

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

def sendEmail(Email,Password,ToAddress):
    msg = MIMEText('Hello, This is a test email')
    msg['Subject'] = "Some subject"
    msg['from'] = Email
    msg['To'] = ToAddress
    server = smtplib.SMTP('', 587)
    server.sendmail(Email, ToAddress, msg.as_string())


Leave a Reply