Skip to content

Instantly share code, notes, and snippets.

@gdm
Created March 21, 2016 11:13
Show Gist options
  • Save gdm/263a77ca7d4e8d981533 to your computer and use it in GitHub Desktop.
Save gdm/263a77ca7d4e8d981533 to your computer and use it in GitHub Desktop.
Send mail to multiple recipients
import smtplib
import sys, os
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
msg = MIMEMultipart()
msg['From'] = '[email protected]'
recipients = os.environ['MAILTO'].split(',')
msg['To'] = ", ".join(recipients)
msg['Subject'] = os.environ['MAILSUBJECT']
message = os.environ['MAILMSG']
msg.attach(MIMEText(message))
mailserver = smtplib.SMTP('relay-smtp.mailrelay.com',25)
mailserver.ehlo()
mailserver.sendmail('[email protected]', recipients, msg.as_string())
mailserver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment