Created
March 21, 2016 11:13
-
-
Save gdm/263a77ca7d4e8d981533 to your computer and use it in GitHub Desktop.
Send mail to multiple recipients
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 | |
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