Added send-email feature

This commit is contained in:
2023-09-11 21:58:24 +04:00
parent 6d45d1c604
commit a1b3d23c37
10 changed files with 161 additions and 38 deletions

37
src/app/utils/email.py Normal file
View File

@@ -0,0 +1,37 @@
from functools import partial
from fastapi_mail import (
FastMail,
MessageSchema,
ConnectionConfig,
MessageType
)
from app.core.config import settings
def send_email_notification(
subject: str,
body: str
) -> partial:
if settings.EMAIL_RECIPIENTS:
conf = ConnectionConfig(
MAIL_USERNAME = settings.SMTP_USER,
MAIL_PASSWORD = settings.SMTP_PASSWORD,
MAIL_FROM = settings.SMTP_USER,
MAIL_PORT = settings.SMTP_PORT,
MAIL_SERVER = settings.SMTP_HOST,
MAIL_SSL_TLS = settings.SMTP_SSL_TLS,
MAIL_STARTTLS = True
)
message = MessageSchema(
subject = subject,
recipients = settings.EMAIL_RECIPIENTS,
body = body,
subtype=MessageType.plain
)
fast_mail = FastMail(conf)
return partial(fast_mail.send_message, message)