Mercurial > hg > python
view sendpwf.py @ 45:7d4da4e72d37
fix argv handling
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Tue, 05 Jul 2022 10:22:50 +0100 |
parents | 737cd0fd5adb |
children |
line wrap: on
line source
#!/usr/bin/python3 """Send my encrypted pw files to joanna, james and emma""" from email.message import EmailMessage from email.policy import SMTP import smtplib, sys if len(sys.argv)>0 and sys.argv[1]=='-d': sys.argv.pop(1) debug=sys.argv.pop(1) else: debug=None date=sys.argv[1] m=EmailMessage(policy=SMTP) m['From']='ht@home.hst.name' m['To']="Emma JD Boland <emma.jd.boland@gmail.com>, James Thompson <jamesejthompson@gmail.com>, Joanna Thompson <joannat.is@gmail.com>" m['Cc']="Catharine Ward Thompson <catharine122@gmail.com>" m['Subject']='Monthly distro' m.set_content("""As promised ht """) for f in ['password_intro_%s.txt.gpg','passwords_%s.gpg']: ff=f%date with open(ff,'rb') as fp: data=fp.read() m.add_attachment(data, maintype='application', subtype='octet-stream', disposition='attachment', filename=ff) if debug: with open(debug,'wb') as dbf: dbf.write(m.as_bytes()) else: server=smtplib.SMTP('localhost') server.send_message(m) server.close()