|
@@ -69,6 +69,7 @@ class EmailSender(object):
|
69
|
69
|
logger.info(self, 'Connecting from SMTP server {}'.format(self._smtp_config.server))
|
70
|
70
|
self._smtp_connection = smtplib.SMTP(self._smtp_config.server, self._smtp_config.port)
|
71
|
71
|
self._smtp_connection.ehlo()
|
|
72
|
+
|
72
|
73
|
if self._smtp_config.login:
|
73
|
74
|
try:
|
74
|
75
|
starttls_result = self._smtp_connection.starttls()
|
|
@@ -82,9 +83,12 @@ class EmailSender(object):
|
82
|
83
|
logger.debug(self, 'SMTP login result: {}'.format(login_res))
|
83
|
84
|
except Exception as e:
|
84
|
85
|
logger.debug(self, 'SMTP login error: {}'.format(e.__str__()))
|
85
|
|
-
|
|
86
|
+ raise e
|
|
87
|
+
|
86
|
88
|
logger.info(self, 'Connection OK')
|
87
|
89
|
|
|
90
|
+
|
|
91
|
+
|
88
|
92
|
def disconnect(self):
|
89
|
93
|
if self._smtp_connection:
|
90
|
94
|
logger.info(self, 'Disconnecting from SMTP server {}'.format(self._smtp_config.server))
|
|
@@ -96,7 +100,7 @@ class EmailSender(object):
|
96
|
100
|
if not self._is_active:
|
97
|
101
|
logger.info(self, 'Not sending email to {} (service desactivated)'.format(message['To']))
|
98
|
102
|
else:
|
99
|
|
- self.connect() # Acutally, this connects to SMTP only if required
|
|
103
|
+ self.connect() # Actually, this connects to SMTP only if required
|
100
|
104
|
logger.info(self, 'Sending email to {}'.format(message['To']))
|
101
|
105
|
self._smtp_connection.send_message(message)
|
102
|
106
|
|