-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathconnection.py
38 lines (26 loc) · 980 Bytes
/
connection.py
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
33
34
35
36
37
38
from subprocess import PIPE, STDOUT, Popen
from flask_sendmail.message import Message
class Connection(object):
"""Handles connection to host."""
def __init__(self, mail, max_emails=None):
self.mail = mail
self.app = self.mail.app
self.suppress = self.mail.suppress
self.max_emails = max_emails or self.mail.max_emails or 0
self.fail_silently = self.mail.fail_silently
def __enter__(self):
pass
def send(self, message):
sm = Popen([self.mail.mailer, self.mail.mailer_flags], stdin=PIPE,
stdout=PIPE, stderr=STDOUT)
sm.stdin.write(message.dump().encode())
sm.communicate()
return sm.returncode
def __exit__(self, exc_type, exc_value, tb):
pass
def send_message(self, *args, **kwargs):
"""
Shortcut for send(msg).
Takes same arguments as Message constructor.
"""
self.send(Message(*args, **kwargs))