Initial commit

This commit is contained in:
2026-04-16 13:51:10 +03:00
commit a0724af6f1
38 changed files with 2453 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
import aiosmtplib
from email.message import EmailMessage
from src.application.contracts.i_sender import ISender
class EmailSender(ISender):
def __init__(
self,
host: str,
port: int,
username: str,
password: str,
from_addr: str,
use_tls: bool = True,
timeout: int = 10,
):
self._host = host
self._port = port
self._username = username
self._password = password
self._from_addr = from_addr
self._use_tls = use_tls
self._timeout = timeout
async def send(self, to: str, subject: str, body: str, plain: str | None = None) -> None:
message = EmailMessage()
message["From"] = self._from_addr
message["To"] = to
message["Subject"] = subject
if plain:
message.set_content(plain)
message.add_alternative(body, subtype="html")
else:
message.set_content(body, subtype="html")
await aiosmtplib.send(
message,
hostname=self._host,
port=self._port,
username=self._username,
password=self._password,
use_tls=True,
timeout=self._timeout,
)