Files
awesome-python/website/data/category_intros/email.md
T
Vinta ChenandClaude 0d72391733 docs: add Email category intro
The Email category page had no intro, so its meta description fell back to generic text and readers got no guidance on which library to pick.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-09-27 08:25:37 +08:00

1.4 KiB

One function call sends mail through Gmail or another SMTP server with yagmail. This Python email library aims to make sending mail painless.

How to choose:

  • Gmail: yagmail, with an app password or OAuth2
  • Another SMTP server: yagmail, pointed at its host
  • An asyncio app: yagmail's async client

yagmail is a wrapper around smtplib's SMTP connection that connects to Gmail unless you pass another host. It builds the message for you: call send() with the recipients, a subject, and contents, a list whose strings it reads as a local file, HTML, or text. So one call sends text, HTML, and attachments. Wrap a string in yagmail.raw when it must stay plain text. In asyncio code, use its async client as an async context manager.

Keep your password out of your script. Install yagmail[all] to get keyring, then register your credentials once with yagmail.register(), and yagmail reads them from your system keyring. For Gmail, that password is an app password. For credentials you can revoke, use OAuth2: whoever gets its token file can send mail, but nothing else.