forked from cosmicpython/code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotifications.py
More file actions
29 lines (20 loc) · 829 Bytes
/
notifications.py
File metadata and controls
29 lines (20 loc) · 829 Bytes
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
# pylint: disable=too-few-public-methods
import abc
import aiosmtplib
from allocation.app.settings import settings
class AbstractNotifications(abc.ABC):
@abc.abstractmethod
async def send(self, destination, message):
raise NotImplementedError
DEFAULT_HOST = settings.get_email_host_and_port()["host"]
DEFAULT_PORT = settings.get_email_host_and_port()["port"]
class EmailNotifications(AbstractNotifications):
def __init__(self, smtp_host=DEFAULT_HOST, port=DEFAULT_PORT):
self.server = aiosmtplib.SMTP(smtp_host, port=port)
async def send(self, destination, message):
msg = f"Subject: allocation service notification\n{message}"
await self.server.sendmail(
from_addr="allocations@example.com",
to_addrs=[destination],
msg=msg,
)