Skip to content

Instantly share code, notes, and snippets.

@alaudet
Last active August 29, 2015 14:03
Show Gist options
  • Save alaudet/3c5b9039b56d684e71c2 to your computer and use it in GitHub Desktop.
Save alaudet/3c5b9039b56d684e71c2 to your computer and use it in GitHub Desktop.
smtplib gmail multiple recipients
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