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:
smtp-mail.outlook.com(587)
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('smtp-mail.outlook.com', 587)
server.starttls()
server.ehlo()
server.login(Email,Password)
server.sendmail(Email, ToAddress, msg.as_string())
server.quit()
sendEmail(Email,Password,ToAddress)