Skip to content

Instantly share code, notes, and snippets.

@woulfe68
Last active July 27, 2019 04:31
Show Gist options
  • Save woulfe68/40c4baab2d43b1d653f1aa40907e2cef to your computer and use it in GitHub Desktop.
Save woulfe68/40c4baab2d43b1d653f1aa40907e2cef to your computer and use it in GitHub Desktop.
Send an email with a gmail account using python 3
import smtplib
TO = ['recipient_1@gmail.com', 'recipient_2@gmail.com']
# ^^^ doesnt matter how many you put in
SUBJECT = 'EXAMPLE SUBJECT'
TEXT = 'example text to recipients'
gmail_user = "user@gmail.com"
gmail_password = "password"
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.ehlo()
server.login(gmail_user, gmail_password)
BODY = '\r\n'.join(['To: %s' % TO,
'From: %s' % gmail_user,
'Subject: %s' % SUBJECT,
'', TEXT])
try:
server.sendmail(gmail_user, TO, BODY)
print ('email sent')
except:
print ('error sending mail')
server.quit()
#more up to date version of yzhong52
#has'nt been updated since 2014 so made this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment