API Reference

This page displays a full reference of yagmail’s API.

Authentication

yagmail.register(username, password)[source]

Use this to add a new gmail account to your OS’ keyring so it can be used in yagmail

Another way of authenticating is by passing an oauth2_file to yagmail.SMTP, which is among the safest methods of authentication. Please see the OAuth2 section of the README for further details.

It is also possible to simply pass the password to yagmail.SMTP. If no password is given, yagmail will prompt the user for a password and then store the result in the keyring.

SMTP Client

class yagmail.SMTP(user=None, password=None, host='smtp.gmail.com', port=None, smtp_starttls=None, smtp_ssl=True, smtp_set_debuglevel=0, smtp_skip_login=False, encoding='utf-8', oauth2_file=None, soft_email_validation=True, **kwargs)[source]

E-Mail Contents

class yagmail.raw[source]

Ensure that a string is treated as text and will not receive ‘magic’.

class yagmail.inline[source]

Only needed when wanting to inline an image rather than attach it

Exceptions

Contains the exceptions

exception yagmail.error.YagAddressError[source]

This means that the address was given in an invalid format. Note that From can either be a string, or a dictionary where the key is an email, and the value is an alias {‘sample@gmail.com’, ‘Sam’}. In the case of ‘to’, it can either be a string (email), a list of emails (email addresses without aliases) or a dictionary where keys are the email addresses and the values indicate the aliases. Furthermore, it does not do any validation of whether an email exists.

exception yagmail.error.YagConnectionClosed[source]

The connection object has been closed by the user. This object can be used to send emails again after logging in, using self.login().

exception yagmail.error.YagInvalidEmailAddress[source]

Note that this will only filter out syntax mistakes in emailaddresses. If a human would think it is probably a valid email, it will most likely pass. However, it could still very well be that the actual emailaddress has simply not be claimed by anyone (so then this function fails to devalidate).

Utilities

yagmail.validate.validate_email_with_regex(email_address)[source]

Note that this will only filter out syntax mistakes in emailaddresses. If a human would think it is probably a valid email, it will most likely pass. However, it could still very well be that the actual emailaddress has simply not be claimed by anyone (so then this function fails to devalidate).