fixed body encoding
This commit is contained in:
parent
2f8c765610
commit
cceabfdf91
|
@ -5,6 +5,7 @@ import argparse
|
|||
import calendar
|
||||
import smtplib
|
||||
import sys
|
||||
import codecs
|
||||
|
||||
from datetime import datetime
|
||||
from email.mime.text import MIMEText
|
||||
|
@ -13,10 +14,9 @@ from email import charset
|
|||
|
||||
|
||||
def createMail(args, target_date, diff):
|
||||
fp = open(args.msg_template, 'r')
|
||||
# Create a text/plain message
|
||||
msg = MIMEText(fp.read() % {"date": target_date.strftime("%d.%m.%Y"), "diff":diff.days}, _charset="UTF-8")
|
||||
fp.close()
|
||||
body = codecs.open(args.msg_template, 'r', "utf-8").read() % {"date": target_date.strftime("%d.%m.%Y"), "diff":diff.days}
|
||||
|
||||
msg = MIMEText(body, _charset="UTF-8")
|
||||
|
||||
msg['Subject'] = Header(args.subject, "utf-8")
|
||||
msg['From'] = args.From
|
||||
|
@ -47,7 +47,10 @@ def main(args):
|
|||
msg = createMail(args, target_date, diff)
|
||||
print(type(msg.as_string()))
|
||||
print("msg", msg.as_string())
|
||||
|
||||
|
||||
if args.debug:
|
||||
return
|
||||
|
||||
s = smtplib.SMTP(args.host)
|
||||
s.set_debuglevel(3)
|
||||
s.sendmail(args.From, [args.to], msg.as_string())
|
||||
|
@ -66,6 +69,7 @@ if __name__ == '__main__':
|
|||
parser.add_argument('-f', "--From", default="CTDOReminder <discuss@lists.chaostreff-dortmund.de>", help="mail from")
|
||||
parser.add_argument('-t', "--to", default="discuss@lists.chaostreff-dortmund.de", help="mail to")
|
||||
parser.add_argument('-H', "--host", default="", help="the smtp server to send to")
|
||||
parser.add_argument('-D', "--debug", action="store_true", help="don't send the mail")
|
||||
|
||||
args = parser.parse_args(sys.argv[1:])
|
||||
|
||||
|
|
Loading…
Reference in New Issue