import smtplib
from email.mime.text import MIMEText
msg = MIMEText('There was a terrible error that occured and I wanted you to know!')
msg['Subject'] = 'Hello world'
msg['From'] = 'from@example.com'
msg['To'] = 'to@example.com'
username = 'mailtrap.io username'
password = 'mailtrap.io password'
# The actual mail send
server = smtplib.SMTP('mailtrap.io', 2525)
server.starttls()
server.login(username,password)
server.sendmail('from@example.com', ['to@example.com'], msg.as_string())
server.quit()