MCPcopy Create free account
hub / github.com/CryptoSignal/Crypto-Signal / GmailNotifier

Class GmailNotifier

app/notifiers/gmail_client.py:11–53  ·  view source on GitHub ↗

Class for handling gmail notifications

Source from the content-addressed store, hash-verified

9from notifiers.utils import NotifierUtils
10
11class GmailNotifier(NotifierUtils):
12 """Class for handling gmail notifications
13 """
14
15 def __init__(self, username, password, destination_addresses):
16 """Initialize GmailNotifier class
17
18 Args:
19 username (str): Username of the gmail account to use for sending message.
20 password (str): Password of the gmail account to use for sending message.
21 destination_addresses (list): A list of email addresses to notify.
22 """
23
24 self.logger = structlog.get_logger()
25 self.smtp_server = 'smtp.gmail.com:587'
26 self.username = username
27 self.password = password
28 self.destination_addresses = ','.join(destination_addresses)
29
30
31 @retry(stop=stop_after_attempt(3))
32 def notify(self, message):
33 """Sends the message.
34
35 Args:
36 message (str): The message to send.
37
38 Returns:
39 dict: A dictionary containing the result of the attempt to send the email.
40 """
41
42 header = 'From: %s\n' % self.username
43 header += 'To: %s\n' % self.destination_addresses
44 header += 'Content-Type: text/plain\n'
45 header += 'Subject: Crypto-signal alert!\n\n'
46 message = header + message
47
48 smtp_handler = smtplib.SMTP(self.smtp_server)
49 smtp_handler.starttls()
50 smtp_handler.login(self.username, self.password)
51 result = smtp_handler.sendmail(self.username, self.destination_addresses, message)
52 smtp_handler.quit()
53 return result

Callers 1

__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected