Update EMAIL_DEBUG to use/support evolution

This commit is contained in:
Yingtong Li 2023-05-01 17:37:38 +10:00
parent 5cbb872c8e
commit 4f84e8a99f
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A

View File

@ -1,5 +1,6 @@
# Society Self-Service
# Copyright © 2018-2023 Yingtong Li (RunasSudo)
# Copyright © 2023 MUMUS Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
@ -56,9 +57,9 @@ class Emailer:
def send_raw_mail(self, recipients, subject, content_txt, content_html):
if settings.EMAIL_DEBUG:
with tempfile.NamedTemporaryFile(mode='w', encoding='utf-8', suffix='.eml') as f:
print('Subject:' + subject + '\nContent-Type: multipart/alternative; boundary=boundary\n\n--boundary\nContent-Type: text/html; charset=utf-8\n\n' + content_html + '\n--boundary\nContent-Type: text/plain; charset=utf-8\n\n' + content_txt + '\n--boundary', file=f)
subprocess.run(['thunderbird', f.name])
with tempfile.NamedTemporaryFile(mode='w', encoding='utf-8', suffix='.mbox') as f:
print('From: sender@example.com\nTo: ' + ','.join(recipients) + '\nSubject: ' + subject + '\nContent-Type: multipart/alternative; boundary=boundary\nMessage-ID: <0@example.com>\n\n--boundary\nContent-Type: text/html; charset=utf-8\n\n' + content_html + '\n--boundary\nContent-Type: text/plain; charset=utf-8\n\n' + content_txt + '\n--boundary', file=f)
subprocess.run(['evolution', f.name])
time.sleep(5)
else:
self.boto3_send(