mirror of
https://github.com/aykhans/portfolio-blog.git
synced 2025-09-08 15:10:45 +00:00
Added send-email feature
This commit is contained in:
37
src/app/utils/email.py
Normal file
37
src/app/utils/email.py
Normal 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)
|
Reference in New Issue
Block a user