summaryrefslogtreecommitdiffstats
path: root/accounts/backend/mail/sendmail.py
diff options
context:
space:
mode:
Diffstat (limited to 'accounts/backend/mail/sendmail.py')
-rw-r--r--accounts/backend/mail/sendmail.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/accounts/backend/mail/sendmail.py b/accounts/backend/mail/sendmail.py
index 5ac5d93..1fecedc 100644
--- a/accounts/backend/mail/sendmail.py
+++ b/accounts/backend/mail/sendmail.py
@@ -4,27 +4,30 @@
import subprocess
from email.mime.text import MIMEText
from email.utils import parseaddr
+from jinja2.environment import TemplateModule
from . import Backend
-class SendmailBackend(Backend):
+def safe(s: str):
+ return s.split('\n', 1)[0]
- def _send(self, recipient, content):
- safe = lambda s: s.split('\n', 1)[0]
- msg = MIMEText(content.body(), _charset='utf-8')
- msg['Subject'] = safe(content.subject())
+class SendmailBackend(Backend):
+ def _send(self, recipient: str, content: TemplateModule):
+ msg = MIMEText(content.body(), _charset='utf-8') # type: ignore
+ msg['Subject'] = safe(content.subject()) # type: ignore
msg['To'] = safe(recipient)
- msg['From'] = safe(content.sender())
+ msg['From'] = safe(content.sender()) # type: ignore
envelope = []
- _, address = parseaddr(safe(content.sender()))
+ _, address = parseaddr(safe(content.sender())) # type: ignore
if address != '':
envelope = ['-f', address]
p = subprocess.Popen([self.app.config['SENDMAIL_COMMAND']] +
envelope + ['-t'], stdin=subprocess.PIPE)
+ assert p.stdin
p.stdin.write(msg.as_string().encode("utf-8"))
p.stdin.close()