annotate sendpwf.py @ 44:737cd0fd5adb

works
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Sun, 05 Jun 2022 22:57:31 +0100
parents
children 7d4da4e72d37
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
44
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
1 #!/usr/bin/python3
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
2 """Send my encrypted pw files to joanna, james and emma"""
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
3 from email.message import EmailMessage
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
4 from email.policy import SMTP
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
5
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
6 import smtplib, sys
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
7
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
8 if sys.argv[1]=='-d':
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
9 sys.argv.pop(1)
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
10 debug=sys.argv.pop(1)
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
11 else:
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
12 debug=None
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
13
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
14 date=sys.argv[1]
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
15
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
16
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
17 m=EmailMessage(policy=SMTP)
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
18 m['From']='ht@home.hst.name'
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
19 m['To']="Emma JD Boland <emma.jd.boland@gmail.com>, James Thompson <jamesejthompson@gmail.com>, Joanna Thompson <joannat.is@gmail.com>"
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
20 m['Cc']="Catharine Ward Thompson <catharine122@gmail.com>"
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
21 m['Subject']='Monthly distro'
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
22 m.set_content("""As promised
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
23
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
24 ht
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
25 """)
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
26 for f in ['password_intro_%s.txt.gpg','passwords_%s.gpg']:
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
27 ff=f%date
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
28 with open(ff,'rb') as fp:
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
29 data=fp.read()
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
30 m.add_attachment(data,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
31 maintype='application',
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
32 subtype='octet-stream',
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
33 disposition='attachment',
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
34 filename=ff)
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
35
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
36 if debug:
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
37 with open(debug,'wb') as dbf:
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
38 dbf.write(m.as_bytes())
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
39 else:
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
40 server=smtplib.SMTP('localhost')
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
41 server.send_message(m)
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
42 server.close()