Coverage for fastid / email / client.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-10-18 16:37 +0000

1import asyncio 

2import smtplib 

3from email.mime.multipart import MIMEMultipart 

4from email.mime.text import MIMEText 

5 

6from fastid.auth.schemas import Contact 

7 

8 

9class MailClient: 

10 def __init__( 

11 self, 

12 client: smtplib.SMTP, 

13 *, 

14 mail_from: str, 

15 ) -> None: 

16 self._client = client 

17 self.mail_from = mail_from 

18 

19 async def send(self, contact: Contact, subject: str, content: str) -> None: 

20 await asyncio.to_thread(self._send, contact, subject, content) 

21 

22 def _send(self, contact: Contact, subject: str, content: str) -> None: 

23 msg = MIMEMultipart("alternative") 

24 msg["Subject"] = subject 

25 msg["From"] = f"{self.mail_from}" 

26 msg["To"] = f"<{contact.recipient['email']}>" 

27 msg.attach(MIMEText(content, "html")) 

28 

29 self._client.send_message(msg)