|
@@ -24,9 +24,10 @@ class EmailSender(object):
|
24
|
24
|
this class allow to send emails and has no relations with SQLAlchemy and other tg HTTP request environment
|
25
|
25
|
This means that it can be used in any thread (even through a asyncjob_perform() call
|
26
|
26
|
"""
|
27
|
|
- def __init__(self, config: SmtpConfiguration):
|
|
27
|
+ def __init__(self, config: SmtpConfiguration, really_send_messages):
|
28
|
28
|
self._smtp_config = config
|
29
|
29
|
self._smtp_connection = None
|
|
30
|
+ self._is_active = really_send_messages
|
30
|
31
|
|
31
|
32
|
def connect(self):
|
32
|
33
|
if not self._smtp_connection:
|
|
@@ -52,6 +53,9 @@ class EmailSender(object):
|
52
|
53
|
|
53
|
54
|
|
54
|
55
|
def send_mail(self, message: MIMEMultipart):
|
55
|
|
- self.connect() # Acutally, this connects to SMTP only if required
|
56
|
|
- logger.info(self, 'Sending email to {}'.format(message['To']))
|
57
|
|
- self._smtp_connection.send_message(message)
|
|
56
|
+ if not self._is_active:
|
|
57
|
+ logger.info(self, 'Not sending email to {} (service desactivated)'.format(message['To']))
|
|
58
|
+ else:
|
|
59
|
+ self.connect() # Acutally, this connects to SMTP only if required
|
|
60
|
+ logger.info(self, 'Sending email to {}'.format(message['To']))
|
|
61
|
+ self._smtp_connection.send_message(message)
|