Last active
August 29, 2015 14:03
-
-
Save alaudet/3c5b9039b56d684e71c2 to your computer and use it in GitHub Desktop.
smtplib gmail multiple recipients
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 | |
import string | |
def smtp_gmail(): | |
username = "your smtp username here " | |
password = "your smtp password here" | |
smtp_server = "smtp.gmail.com:587" | |
recipients = ["[email protected]", "[email protected]", "[email protected]"] | |
email_from = "sender email" | |
email_to = ', '.join(recipients) | |
email_body = string.join(( | |
"From: %s" % email_from, | |
"To: %s" % email_to, | |
"Subject: This is my subject line!", | |
"", | |
"This is my message that can also have a %s" % (mystring | |
),), "\r\n" | |
) | |
server = smtplib.SMTP(smtp_server) | |
server.starttls() | |
server.login(username, password) | |
server.sendmail(email_from, recipients, email_body) | |
server.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment