FastAPI Mail


1. Basic SMTP Configuration:

from fastapi_mail import FastMail, MessageSchema
from fastapi_mail.smtp import SMTPConfig

config = SMTPConfig(
    host="smtp.gmail.com",
    port=587,
    username="your_email@gmail.com",
    password="your_password",
)

mail = FastMail(config=config)

2. Send a Simple Email:

message = MessageSchema(
    subject="Test Email",
    recipients=["recipient@example.com"],
    body="Hello, world!",
)

mail.send_message(message)

3. Send an Email with HTML Template:

4. Send an Email with Attachments:

5. Send an Email with Multiple Recipients:

6. Send an Email with BCC Recipients:

7. Send an Email with Custom Headers:

8. Send an Email with Mailgun Configuration:

9. Send an Email with Mandrill Configuration:

10. Send an Email with Sendgrid Configuration:

11. Send an Email with Amazon SES Configuration:

12. Send an Email with GMail OAuth2 Configuration:

13. Send an Email with Custom Sender Address:

14. Send an Email with Reply-To Address:

15. Send an Email with Priority:

16. Send an Email with BCC Recipients:

17. Send an Email with Custom MIME Headers:

18. Send an Email with HTML Body and Plain Text Body:

19. Send an Email with Templates:

20. Send an Email with Custom Message ID:

21. Send an Email with Tracking:

22. Send an Email with Rate Limiting:

23. Send an Email with File Embeddings:

24. Send an Email with Inline Embeddings:

25. Send an Email with Multiple Embed Types:

26. Send an Email with Custom Configuration:

27. Send an Email with Custom Template Dir:

28. Send an Email with Async Send:

29. Send an Email with Background Send:

30. Send an Email with Celery Background Send:

31. Send an Email with Sendgrid ConnectionConfig:

32. Send an Email with Mailgun ConnectionConfig:

33. Send an Email with Mandrill ConnectionConfig:

34. Send an Email with SES ConnectionConfig:

35. Send an Email with Gmail OAuth2 ConnectionConfig:

36. Send an Email with Templates with ConnectionConfig: