You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@community.apache.org by se...@apache.org on 2016/06/21 14:58:56 UTC
svn commit: r1749551 -
/comdev/projects.apache.org/scripts/cronjobs/sendmail.py
Author: sebb
Date: Tue Jun 21 14:58:56 2016
New Revision: 1749551
URL: http://svn.apache.org/viewvc?rev=1749551&view=rev
Log:
Allow code to work with a recipient list
Modified:
comdev/projects.apache.org/scripts/cronjobs/sendmail.py
Modified: comdev/projects.apache.org/scripts/cronjobs/sendmail.py
URL: http://svn.apache.org/viewvc/comdev/projects.apache.org/scripts/cronjobs/sendmail.py?rev=1749551&r1=1749550&r2=1749551&view=diff
==============================================================================
--- comdev/projects.apache.org/scripts/cronjobs/sendmail.py (original)
+++ comdev/projects.apache.org/scripts/cronjobs/sendmail.py Tue Jun 21 14:58:56 2016
@@ -13,17 +13,27 @@ def sendMail(subject, body='', recipient
msg = MIMEText(body)
msg['Subject'] = subject
msg['From'] = sender
- msg['To'] = recipients
+ if isinstance(recipients, str):
+ msg['To'] = recipients
+ else:
+ msg['To'] = ",".join(recipients)
if replyTo != None:
msg['Reply-To'] = replyTo
smtp = smtplib.SMTP('localhost', port)
- smtp.sendmail(sender, [recipients], msg.as_string())
+# smtp.set_debuglevel(True)
+ smtp.sendmail(sender, recipients, msg.as_string())
smtp.quit()
if __name__ == '__main__':
+ import sys
+ port = 25
+ if len(sys.argv) > 1: # argv[0] is the script name
+ port = int(sys.argv[1])
# for testing locally:
# sudo postfix start # MacoxX
# or start a debug server => need to change the SMTP port
# python -m smtpd -n -c DebuggingServer localhost:1025
- sendMail('Test message, please ignore', "Thanks!")
- print("Sent")
\ No newline at end of file
+ sendMail('Test message, please ignore', "Thanks!", port=port)
+ print("Sent")
+ sendMail('Another Test message, please ignore', "Thanks again!", recipients=['a.b.c','d.e.f'], port=port)
+ print("Sent second")