update some mailer method names, add space for clarity

This commit is contained in:
dandds 2018-10-17 15:10:33 -04:00
parent c3f6740083
commit c81eab07f7

View File

@ -21,7 +21,7 @@ class SMTPConnection(MailConnection):
self.use_tls = use_tls self.use_tls = use_tls
@contextmanager @contextmanager
def _host(self): def _connected_host(self):
host = None host = None
if self.use_tls: if self.use_tls:
@ -29,6 +29,7 @@ class SMTPConnection(MailConnection):
host.starttls() host.starttls()
else: else:
host = smtplib.SMTP_SSL(self.server, self.port) host = smtplib.SMTP_SSL(self.server, self.port)
host.login(self.username, self.password) host.login(self.username, self.password)
yield host yield host
@ -40,7 +41,7 @@ class SMTPConnection(MailConnection):
return [] return []
def send(self, message): def send(self, message):
with self._host() as host: with self._connected_host() as host:
host.send_message(message) host.send_message(message)
@ -66,7 +67,7 @@ class Mailer(object):
self.connection = connection self.connection = connection
self.sender = sender self.sender = sender
def _message(self, recipients, subject, body): def _build_message(self, recipients, subject, body):
msg = EmailMessage() msg = EmailMessage()
msg.set_content(body) msg.set_content(body)
msg["From"] = self.sender msg["From"] = self.sender
@ -76,7 +77,7 @@ class Mailer(object):
return msg return msg
def send(self, recipients, subject, body): def send(self, recipients, subject, body):
message = self._message(recipients, subject, body) message = self._build_message(recipients, subject, body)
self.connection.send(message) self.connection.send(message)
@property @property