Created
April 3, 2015 13:38
-
-
Save bot11/7dd3777c942bcc4911aa to your computer and use it in GitHub Desktop.
send mail using gmail.
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
import smtplib | |
gmail_user = "[email protected]" | |
gmail_pwd = "frompwd" | |
TO = '[email protected]' | |
SUBJECT = "Testing sending using gmail" | |
TEXT = "Testing sending mail using gmail servers" | |
server = smtplib.SMTP('smtp.gmail.com', 587) | |
server.ehlo() | |
server.starttls() | |
server.login(gmail_user, gmail_pwd) | |
BODY = '\r\n'.join(['To: %s' % TO, | |
'From: %s' % gmail_user, | |
'Subject: %s' % SUBJECT, | |
'', TEXT]) | |
server.sendmail(gmail_user, [TO], BODY) | |
print ('email sent') | |
#If got the following error: | |
''' | |
Traceback (most recent call last): | |
File "send_from_gmail.py", line 13, in <module> | |
server.login(gmail_user, gmail_pwd) | |
File "/usr/lib/python2.7/smtplib.py", line 615, in login | |
raise SMTPAuthenticationError(code, resp) | |
smtplib.SMTPAuthenticationError: (534, '5.7.14 <https://accounts.google.com/...........................................................................> | |
Please log in via your web browser and\n5.7.14 then try again.\n5.7.14 Learn more at\n5.7.14 https://support.google.com/mail/bin/answer.py?answer=XXXX XXXXXXX.2 - gsmtp') | |
Access : https://www.google.com/settings/security/lesssecureapps and set | |
Access for less secure apps : turn off | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment