import smtplib from email.parser import BytesParser, Parser from email.policy import default headers = Parser(policy=default).parsestr( 'From: Foo Bar \n' 'To: \n' 'Subject: Simple Text Message\n' '\n' 'Email sending example using Python. It\'s Simple Text Message\n') s = smtplib.SMTP('smtp.gmail.com', 587) s.starttls() s.login('gmail@gmail.com', 'gmail\'s password') s.send_message(headers) s.quit()