Coverage for src/core/mail.py: 35%

1 from email.message import EmailMessage

2 import smtplib

3

4 from .settings import MailSettings

5

6

7 class MailClient:

8 def __init__(self, settings: MailSettings):

9 self.settings = settings

10

11 def send(self, recipients: list[str], subject: str, body: str):

12 msg = EmailMessage()

13 msg.set_content(body)

14 server = smtplib.SMTP(self.settings.host, self.settings.port, timeout=5)

15 server.starttls()

16 server.login(self.settings.login, self.settings.password)

17

18 msg = EmailMessage()

19 msg["Subject"] = subject

20 msg.set_content(body)

21 msg["From"] = self.settings.login

22

23 for recipient in recipients:

24 msg["To"] = recipient

25 server.send_message(msg)

26

27 server.quit()