Sending Email Using Python Script (Gmail )
About this Post In this post I will be sharing a simple python script to send email using Python SMTP module. I am taking Gmail example. Prerequisite Python 2 / Python 3 Enable Less Secure App Login (Gmail)- https://myaccount.google.com/lesssecureapps Python Code import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart def mail_using_gmail (): from_email = '-------@gmail.com' to_email = "-------@gmail.com" # Create message container - the correct MIME type is multipart/alternative. msg = MIMEMultipart( 'alternative' ) msg[ 'Subject' ] = "Testing Email Using Python" msg[ 'From' ] = from_email msg[ 'To' ] = to_email # Create the body of the message (a plain-text and an HTML version). text = "This is a test email." part1 = MIMEText(text , 'plain' ) msg.attach(part1) # SMTP client session mail = smtplib.SMTP_SSL(