Created
May 10, 2019 12:04
-
-
Save kovalbogdan95/ce907aecc01f160f87781427a9ab9b25 to your computer and use it in GitHub Desktop.
Send email using smtplib and python2
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 | |
gmail_user = 'user' | |
gmail_password = 'password' | |
sent_from = gmail_user + '@gmail.com' | |
to = ['[email protected]', '[email protected]', '[email protected]'] | |
subject = 'OMG Super Important Message' | |
body = 'Hey, what"s up?\n\n- You' | |
email_text = """\ | |
From: %s | |
To: %s | |
Subject: %s | |
%s | |
""" % (sent_from, ", ".join(to), subject, body) | |
server = smtplib.SMTP_SSL('smtp.gmail.com', 465) | |
server.ehlo() | |
server.login(gmail_user, gmail_password) | |
server.sendmail(sent_from, to, email_text) | |
server.close() | |
print 'Email sent!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment