24 lines
761 B
Python
24 lines
761 B
Python
from fastapi_mail import ConnectionConfig, FastMail
|
|
from config import SMTP_USERNAME, SMTP_PASSWORD, SMTP_PORT, SMTP_HOST
|
|
from emails.emails import Email
|
|
|
|
|
|
class Mailer:
|
|
def __init__(self):
|
|
self.conf = ConnectionConfig(
|
|
MAIL_USERNAME=SMTP_USERNAME,
|
|
MAIL_PASSWORD=SMTP_PASSWORD,
|
|
MAIL_FROM="michalkv@gmail.com",
|
|
MAIL_FROM_NAME="Polétání",
|
|
MAIL_PORT=SMTP_PORT,
|
|
MAIL_SERVER=SMTP_HOST,
|
|
MAIL_STARTTLS=False,
|
|
MAIL_SSL_TLS=True,
|
|
USE_CREDENTIALS=True,
|
|
TEMPLATE_FOLDER='/app/src/emails/templates/html'
|
|
)
|
|
|
|
async def send(self, mail: Email):
|
|
fm = FastMail(self.conf)
|
|
await fm.send_message(mail, mail.template)
|