Files
awesome-python/website/data/category_intros/email.md
T
Vinta ChenandClaude 1386e49f2f docs: reword Email category intro lead
Its second sentence paired aiosmtplib and yagmail with their jobs in the same compressed two-pick frame the Admin Panels lead uses.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-02 16:40:58 +08:00

2.1 KiB

Sending from Django, you learn no new Python email library API: django-anymail runs send_mail(). Async code sends mail through aiosmtplib.

How to choose:

  • A Django app sending through Amazon SES, Mailgun, Postmark, or another email service: django-anymail
  • A Django app that tracks delivery or receives email through that service: django-anymail
  • Async code talking to an SMTP server: aiosmtplib
  • A script sending from Gmail, or any SMTP account, with attachments: yagmail

django-anymail extends Django's django.core.mail with features email services add, through one API that doesn't lock your code to one service. Change Django's email backend to Anymail's backend for your service, and send_mail(), EmailMessage, and even mail_admins() send through it unchanged. Send from a background task, not the view: Anymail calls that a best practice for sending email from Django, since your views respond faster. To track delivery or receive email, connect the service's webhooks to Anymail's Django signals, and protect them with https and a shared secret.

aiosmtplib is an async version of smtplib, with similar APIs. Build each message as the standard library's EmailMessage, which makes headers easier to work with. Then pass it to the send() coroutine, which the docs recommend for most use cases.

yagmail aims to make sending email as simple as possible, with Gmail as its default server. Its contents argument is guessed item by item: a path to a local file becomes an attachment, valid HTML becomes HTML, and anything else is text. For Gmail, sign in with an app password or OAuth2.