Skip to content

ZackPlauche/python-gmail

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Gmail 🐍📨

The bare minimum api to send emails from your gmail account using Python.

Features

  • Easy API
  • Common defaults for using smtp with Gmail so you don't have to think about it.
  • Supports emojis in text by default

Not Features

  • Getting previous emails
  • Getting contacts
  • Changing email settings
  • Etc.

Requirements

  • Must have a Gmail account
  • Must have 2 factor authentication setup on your gmail account
  • Must create an app password for your gmail account

Installation

Pip install this for your system:

pip install git+https://www.github.com/zackplauche/python-gmail

Quickstart

Create your instance and send an email

>>> from gmail import Client
>>> client = Client(email='[email protected]', app_password='aaaa aaaa aaaa aaaa')
>>> client.send_email(to='[email protected]', subject='Hello! 👋', body='How are you today? 👀❓')

or send to multiple emails separately

>>> client.send_email(to=['[email protected]', '[email protected]'], subject='Hello! 👋', body='How are you today? 👀❓')

That's it!

Basic Usage

Creating an Instance

You can create a gmail instance from just your gmail account email and your gmail account app password

>>> from gmail import Client
>>> client = Client(email='[email protected]', app_password='aaaa aaaa aaaa aaaa')

Creating an Instance from environment variables

If you wish to create instantiate a client more securely, you can create your instance from environment variables using the GMAIL_EMAIL and GMAIL_APP_PASSWORD environment variable names.

  1. Create a .env file in your directory and add the following:
GMAIL_EMAIL=[email protected]
GMAIL_APP_PASSWORD=aaaa aaaa aaaa aaaa
  1. Create your instance:
>>> client = Client.from_env()

Sending Emails

You can send an email by writing the following:

>>> client.send_email(
...     to='[email protected]',
...     subject='Hello! 👋',
...     body='How are you doing? 👀❓'
... )

This will send an email with a subject and body.

Important Note: Where usually you would see the name of your gmail account, you will only see your email unless you specify a name in the from_ field, like this:

>>> client.send_email(
...     from_=f'Example Email <{client.email}>', 
...     to='[email protected]',
...     subject='Howdy! 🤠',
...     body='Good morning neighbor! ☀️🏠🥓'
... )

For convenience, you can also create this at the instantiation and not have to think about it later:

>>> # Name will be Bob <[email protected]>
>>> client = Client(email='[email protected]', name='Bob', app_password=...)
>>> # or from env vars
>>> client = gmail.from_env(name='Bob')  # OR set GMAIL_NAME as an environment variable

Then you can send an email without the from_ argument and it will have your name in it.

Authors Note and Links

Enjoy! 📨📨📨

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages