blob: 84900db7a6aa54b24f0a66e52e4ab80c0d9dd3b2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# -*- coding: utf-8 -*-
import subprocess
from email.mime.text import MIMEText
from email.utils import parseaddr
from . import Backend
class SendmailBackend(Backend):
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())
msg['To'] = safe(recipient)
msg['From'] = safe(content.sender())
envelope = []
_, address = parseaddr(safe(content.sender()))
if address != '':
envelope = ['-f', address]
p = subprocess.Popen([self.app.config['SENDMAIL_COMMAND']] +
envelope + ['-t'], stdin=subprocess.PIPE)
p.stdin.write(msg.as_string())
p.stdin.close()
if p.wait() != 0:
raise RuntimeError('sendmail terminated with %d' % p.returncode)
|