prepare_email_forward (878B)
1 #!/usr/bin/env python3 2 # adapted from https://stackoverflow.com/a/16509278 3 4 import sys 5 import os.path as op 6 from email.mime.multipart import MIMEMultipart 7 from email.mime.base import MIMEBase 8 from email.mime.text import MIMEText 9 from email.utils import COMMASPACE, formatdate, make_msgid 10 from email import encoders 11 12 FROM = sys.argv[1] 13 TO = sys.argv[2] 14 SUBJECT = sys.argv[3] 15 IN_REPLY_TO = sys.argv[4] 16 FILE = sys.argv[5] 17 TEXT = sys.argv[6] 18 19 msg = MIMEMultipart() 20 msg['From'] = FROM 21 msg['To'] = TO 22 msg['Date'] = formatdate(localtime=True) 23 msg['Subject'] = SUBJECT 24 msg['In-Reply-To'] = IN_REPLY_TO 25 msg['Message-ID'] = make_msgid() 26 27 msg.attach(MIMEText(TEXT)) 28 29 part = MIMEBase('message', "rfc822") 30 with open(FILE, 'rb') as file: 31 part.set_payload(file.read()) 32 encoders.encode_base64(part) 33 part.add_header('Content-Disposition', 'inline') 34 msg.attach(part) 35 36 print (msg.as_string())