Skip to content

Instantly share code, notes, and snippets.

@govindsharma7
Forked from yzhong52/send_an_email.py
Created June 3, 2018 05:56
Show Gist options
  • Save govindsharma7/8df8d9c92dea7a7d4eef16d9d79eacbc to your computer and use it in GitHub Desktop.
Save govindsharma7/8df8d9c92dea7a7d4eef16d9d79eacbc to your computer and use it in GitHub Desktop.
Send an email with a gmail account using python 3
# smtplib module send mail
import smtplib
TO = 'recipient@mailservice.com'
SUBJECT = 'TEST MAIL'
TEXT = 'Here is a message from python.'
# Gmail Sign In
gmail_sender = 'sender@gmail.com'
gmail_passwd = 'password'
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login(gmail_sender, gmail_passwd)
BODY = '\r\n'.join(['To: %s' % TO,
'From: %s' % gmail_sender,
'Subject: %s' % SUBJECT,
'', TEXT])
try:
server.sendmail(gmail_sender, [TO], BODY)
print ('email sent')
except:
print ('error sending mail')
server.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment