changeset 19:535e3327ed1b

add support for specifying From:
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Sun, 31 Jan 2021 19:40:26 +0000
parents 1cef0e5f5851
children 69a494ef1a58
files mailer.py
diffstat 1 files changed, 12 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mailer.py	Mon Jul 20 11:21:30 2020 +0100
+++ b/mailer.py	Sun Jan 31 19:40:26 2021 +0000
@@ -1,6 +1,6 @@
 #!/usr/bin/python
 '''Attempt at flexible mailout functionality
-Usage: mailer.py [-n] [-s] [-C cc string] [-c COLSPEC[,COLSPEC]*] [-B bcc string] [-b COLSPEC[,COLSPEC]*] [-S col[,col]*] [-a COLSPEC[,COLSPEC]*] [-p COLPAT]* [-SA file[,file]*] [-R reply-to] [-m .sigfilename] COLSPEC[,COLSPEC]* subject {addr-file|-} body-file
+Usage: mailer.py [-n] [-s] [-C cc string] [-c COLSPEC[,COLSPEC]*] [-B bcc string] [-b COLSPEC[,COLSPEC]*] [-S col[,col]*] [-a COLSPEC[,COLSPEC]*] [-p COLPAT]* [-SA file[,file]*] [-R reply-to] [-f from] [-m .sigfilename] COLSPEC[,COLSPEC]* subject {addr-file|-} body-file
 
 Sends the body as a message from me with subject to destinations per
 lines in the addr-file selected by COLSPECs (to:) or -c/-b COLSPECs (Cc:/Bcc:)
@@ -18,6 +18,7 @@
 -S for columns to substitute as such
 -p for augmentation pattern for a column
 -R for replyTo address
+-f for fromName, defaults to $USER@$HOSTNAME
 -m for .sig file, None for none
 
 COLSPEC is of the form a[:n[:f[:g]]] selects from addr-file, which must be tsv
@@ -48,7 +49,7 @@
 
 All column indices are 1-origin, as for cut'''
 
-import smtplib, sys, re, os.path, codecs
+import smtplib, sys, re, os, os.path, codecs
 from email.mime.text import MIMEText
 
 addrPat=re.compile("<([^>]*)>")
@@ -251,6 +252,7 @@
 dryrun=False
 replyTo=None
 sigfile=None
+fromName='%s@%s'%(os.getenv('USER'),os.getenv('HOSTNAME'))
 
 sys.argv.pop(0)
 doSub=False
@@ -330,6 +332,12 @@
       replyTo=sys.argv.pop(0)
     else:
       usage('reply to')
+  elif sys.argv[0]=='-f':
+    sys.argv.pop(0)
+    if sys.argv:
+      fromName=sys.argv.pop(0)
+    else:
+      usage('from name')
   elif sys.argv[0]=='-m':
     sys.argv.pop(0)
     if sys.argv:
@@ -434,8 +442,9 @@
   if dryrun:
     print recips
     print msg.keys()
+    print 'From: %s'%fromName
     print msg.as_string()
     exit()
   print "mailing to %s"%recips
-  mailer.sendmail("ht@inf.ed.ac.uk",recips,msg.as_string())
+  mailer.sendmail(fromName,recips,msg.as_string())
 mailer.quit()