yagmail (Yet Another GMAIL client) is a Python library designed to simplify sending emails, particularly with Gmail accounts, by abstracting away the complexities of SMTP, MIME, and headers. It is currently at version 0.15.293 and is actively maintained, with regular updates addressing features and compatibility.
pip install yagmail[all]Verified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates sending a basic email using yagmail with an App Password (recommended over your main Gmail password). For enhanced security, especially in production, consider setting up OAuth2 authentication as detailed in yagmail's documentation. Ensure your sender email and password (or app password) are configured, ideally via environment variables.
Use Google App Passwords for programmatic access (if 2FA is enabled) or configure OAuth2 authentication. Refer to Google's and yagmail's official documentation for setup.
Utilize `keyring` (installed with `yagmail[all]`) to securely store credentials (`yagmail.register('your_email@gmail.com', 'your_password')`) or implement OAuth2 as per yagmail's documentation. For basic use, consider environment variables for App Passwords.Ensure your HTML content is explicitly formatted as HTML. For pure plain text, use separate entries in the `contents` list. If experiencing issues, explicitly wrap HTML in `yagmail.inline()` or use HTML files as attachments.
If `pip install yagmail[all]` fails, try `pip install yagmail` first, then install `keyring` and `dkimpy` separately if needed and troubleshoot their individual installations.
Always explicitly specify the 'to' recipient using `to='recipient@example.com'` or a list of recipients.
Generate and use an App Password from your Google Account security settings (myaccount.google.com/apppasswords) instead of your regular Gmail password.
Install the library using pip: `pip install yagmail`
Provide your Gmail password (an App Password is recommended for 2FA accounts) as the second argument: `yag = yagmail.SMTP('your_email@gmail.com', 'your_app_password')`Ensure your firewall, antivirus, or network settings are not blocking outbound connections on SMTP ports (587 for TLS, 465 for SSL) and that you have a stable internet connection.