/
woodpecker86
/
cosmic-python-code
Обзор
Документация
Войти
/
woodpecker86
/
cosmic-python-code
Код
Запросы
0
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/allocation/adapters/notifications.py
28 строк
811 B
Harry
switch to a notifications class [notifications_class]
01 мар 2024, 18:05
01 мар 2024, 18:05
d6141c7
Код
Авторство
О чём код?
# pylint: disable=too-few-public-methods import abc import smtplib from allocation import config class AbstractNotifications(abc.ABC): @abc.abstractmethod def send(self, destination, message): raise NotImplementedError DEFAULT_HOST = config.get_email_host_and_port()["host"] DEFAULT_PORT = config.get_email_host_and_port()["port"] class EmailNotifications(AbstractNotifications): def __init__(self, smtp_host=DEFAULT_HOST, port=DEFAULT_PORT): self.server = smtplib.SMTP(smtp_host, port=port) self.server.noop() def send(self, destination, message): msg = f"Subject: allocation service notification\n{message}" self.server.sendmail( from_addr="allocations@example.com", to_addrs=[destination], msg=msg, )