Created
May 18, 2014 19:54
-
-
Save yzhong52/d703ec82aeee24164f0c to your computer and use it in GitHub Desktop.
Send an email with a gmail account using python 3
This file contains 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
# smtplib module send mail | |
import smtplib | |
TO = '[email protected]' | |
SUBJECT = 'TEST MAIL' | |
TEXT = 'Here is a message from python.' | |
# Gmail Sign In | |
gmail_sender = '[email protected]' | |
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() |
Done I found a Way:
BODY = '\r\n'.join([ 'From: %s' % gmail_sender, 'Subject: %s' % SUBJECT, '', TEXT])
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to add Bcc?