{"id":5555,"library":"yagmail","title":"yagmail","description":"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.","status":"active","version":"0.15.293","language":"en","source_language":"en","source_url":"https://github.com/kootenpv/yagmail","tags":["email","smtp","gmail","automation","client","oauth2"],"install":[{"cmd":"pip install yagmail[all]","lang":"bash","label":"Recommended installation with keyring and dkimpy support"},{"cmd":"pip install yagmail","lang":"bash","label":"Basic installation (if 'all' extra causes issues)"}],"dependencies":[{"reason":"Used for inline CSS in HTML emails.","package":"premailer","optional":false},{"reason":"Recommended for securely storing credentials, avoiding plain-text passwords in scripts.","package":"keyring","optional":true},{"reason":"For DomainKeys Identified Mail (DKIM) signing.","package":"dkimpy","optional":true}],"imports":[{"symbol":"SMTP","correct":"from yagmail import SMTP"}],"quickstart":{"code":"import yagmail\nimport os\n\n# It's recommended to use App Passwords for Gmail or OAuth2.\n# Store your email and app password in environment variables for security.\n# For OAuth2, configure it via yagmail.SMTP('your_email@gmail.com', oauth2_file='path/to/oauth2_creds.json')\n# See yagmail docs for detailed OAuth2 setup.\n\nSENDER_EMAIL = os.environ.get('YAGMAIL_SENDER_EMAIL', 'your_email@gmail.com')\nSENDER_APP_PASSWORD = os.environ.get('YAGMAIL_SENDER_APP_PASSWORD', 'your_app_password')\nRECIPIENT_EMAIL = os.environ.get('YAGMAIL_RECIPIENT_EMAIL', 'recipient@example.com')\n\ntry:\n    # Initialize yagmail with your Gmail account and app password\n    yag = yagmail.SMTP(user=SENDER_EMAIL, password=SENDER_APP_PASSWORD)\n\n    # Send an email\n    subject = 'Hello from yagmail!'\n    contents = [\n        'This is the body of the email.',\n        'You can also send HTML content.',\n        '<p>This is <b>bold</b> HTML content!</p>'\n    ]\n\n    yag.send(\n        to=RECIPIENT_EMAIL,\n        subject=subject,\n        contents=contents\n    )\n    print(f'Email sent successfully from {SENDER_EMAIL} to {RECIPIENT_EMAIL}')\nexcept Exception as e:\n    print(f'Failed to send email: {e}')","lang":"python","description":"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."},"warnings":[{"fix":"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.","message":"Google has deprecated 'Less secure app access'. Older tutorials suggesting this method will no longer work. Attempting to use your main Gmail password without 2FA and an App Password will result in an `SMTPAuthenticationError` or similar.","severity":"breaking","affected_versions":"All versions (due to Google's policy change)"},{"fix":"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.","message":"Providing your main Gmail password directly in the script is a security risk and is discouraged. yagmail prefers using `keyring` for secure storage or OAuth2.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"When sending HTML content, newline characters (\\n) in plain strings might be automatically converted to `<br>` tags. This behavior can be unexpected if you're mixing plain text and HTML.","severity":"gotcha","affected_versions":"Potentially all versions (reported in older issues, behavior might persist for certain content types)"},{"fix":"If `pip install yagmail[all]` fails, try `pip install yagmail` first, then install `keyring` and `dkimpy` separately if needed and troubleshoot their individual installations.","message":"Installation with `pip install yagmail[all]` can sometimes fail due to `keyring` or `dkimpy` dependencies, especially on certain operating systems or Python environments.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always explicitly specify the 'to' recipient using `to='recipient@example.com'` or a list of recipients.","message":"When using `yagmail.SMTP()`, if no explicit 'to' argument is provided in `send()`, the email defaults to being sent to the sender's own address.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}