[Zope-CVS] CVS: Packages/TestScripts - mailer.py:1.2

Chris Withers chrisw@nipltd.com
Thu, 7 Mar 2002 09:49:21 -0500


Update of /cvs-repository/Packages/TestScripts
In directory cvs.zope.org:/tmp/cvs-serv19856

Modified Files:
	mailer.py 
Log Message:
New mailer that allows explicit from address (smile Shane :-)

=== Packages/TestScripts/mailer.py 1.1 => 1.2 ===
 
 # mail a message
-def send(address,subject='',body='',template=template,smtp_server='localhost'):
-    message = template % {'from':address,
+def send(address,subject='',body='',template=template,smtp_server='localhost',from_address=None):
+    """
+    address      - address to send mail to
+    subject      - subject line for the message
+    template     - the template to use to assemble the mail.
+                   See 'template' above for an example.
+    smptp_server - the SMTP server to use to send the mail
+    from_address - the from address to set on the message. If ommitted, 'address'
+                   will be used in its place.
+    """
+    
+    if from_address is None:
+        from_address = address
+        
+    message = template % {'from':from_address,
                           'to':address,
                           'subject':subject,
                           'body':body}
@@ -39,3 +52,11 @@
 
     server = SMTP(smtp_server)
     server.sendmail(from_a,to_a,message)
+
+if __name__=='__main__':
+    # send a test messasge
+    send('mailer-test@squishdot.org',
+         'Test Message',
+         'Body',
+         smtp_server='smtp.nipltd.com',
+         from_address='Some Spammer<spam@squishdot.org>')