from fastapi_mail.fastapi import FastMail, ConnectionConfig
from fastapi_mail.smtp import SMTPConfig
custom_config = SMTPConfig(
host="mail.example.com",
port=25,
username="admin",
password="secret",
)
connection_config = ConnectionConfig(
SECRET="SECRET_KEY",
MAIL_USERNAME="admin",
MAIL_PASSWORD="secret",
MAIL_FROM="admin@example.com",
MAIL_FROM_NAME="John Doe",
MAIL_PORT=25,
MAIL_SERVER="mail.example.com",
MAIL_TLS=True,
MAIL_SSL=False,
USE_CREDENTIALS=True,
VALIDATE_CERTS=True,
# Additional configuration options
_options={
"disable_authentication": True,
"timeout": 30,
"debug": True,
},
)
mail = FastMail(config=custom_config, connection_config=connection_config)
message = MessageSchema(
subject="Test Email",
recipients=["recipient@example.com"],
body="Hello, world!",
)
mail.send_message(message)