Last active
July 27, 2019 04:31
-
-
Save woulfe68/40c4baab2d43b1d653f1aa40907e2cef to your computer and use it in GitHub Desktop.
Send an email with a gmail account using python 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import smtplib | |
TO = ['[email protected]', '[email protected]'] | |
# ^^^ doesnt matter how many you put in | |
SUBJECT = 'EXAMPLE SUBJECT' | |
TEXT = 'example text to recipients' | |
gmail_user = "[email protected]" | |
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