You are here: Home » NewsFeeds » Yagmail: sending mails from Python the easy way

Yagmail: sending mails from Python the easy way

This document aims to show how to use yagmail in your programs.
Most of what is shown here is also available to see in the
README, some content may be
duplicated for completeness.

Start a Connection
As mentioned in Configuring Credentials, there
are three ways to initialize a connection by instantiating
1. With Username and Password:
e.g. yagmail.SMTP(‘mygmailusername’, ‘mygmailpassword’)
This method is not recommended, since you would be storing
the full credentials to your account in your script in plain text.
A better alternative is using keyring, as described in the
following section:
2. With Username and keyring:
After registering a keyring entry for yagmail, you can
instantiate the client by simply passing your username, e.g.
3. With keyring and .yagmail:
As explained in the Setup documentation, you can also
omit the username if you have a .yagmail file in your
home folder, containing just your GMail username. This way,
you can initialize yagmail.SMTP without any arguments.
4. With OAuth2:
This is probably the safest method of authentication, as you
can revoke the


Original article