Skip to main content

Django Gmail API backend

Email backend for Django which sends email via the Gmail API

The simple SMTP protocol is disabled by default for Gmail users, since this is included in the Less Secure Apps (LSA) category. The advice is to use SMTP+OAuth or to use the Gmail API directly. This package implements the second option as a Django email backend.

Installation

Install the package

pip install django-gmailapi-backend

Configuration

In your settings.py:

  1. Add the module into the INSTALLED_APPS

    INSTALLED_APPS = [
        ...
        'gmailapi_backend',
        ...
    ]
    
  2. Set the email backend

    EMAIL_BACKEND = 'gmailapi_backend.mail.GmailBackend'
    
  3. Define the configuration parameters from your Gmail developer account (see next section)

    GMAIL_API_CLIENT_ID = 'client_id'
    GMAIL_API_CLIENT_SECRET = 'client_secret'
    GMAIL_API_REFRESH_TOKEN = 'refresh_token'
    

Configure the Gmail credentials

For using this package you need to obtain the OAuth credentials for a valid Gmail account.

This package includes the script linked in the documentation above, which simplifies the setup of the API credentials. The following outlines the key steps:

  1. Create a project in the Google developer console, https://console.cloud.google.com/
  2. Enable the Gmail API
  3. Create OAuth 2.0 credentials
  4. Create a valid refresh_token using the helper script included in the package:
    gmail_oauth2 --generate_oauth2_token \
      --client_id="<client_id>" \
      --client_secret="<client_secret>" \
      --scope="https://www.googleapis.com/auth/gmail.send"
    

[!NOTE] OOB flow is deprecated so --generate_oauth2_token can fail. To overcome this issue try instead --ugo2t option with the following syntax

gmail_oauth2 --ugo2t \
  --credentials_path="<credentials_relative_path>" # need to be download from gcp after creating an Oauth2 client

Release files for django-gmailapi-backend 0.3.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-gmailapi-backend 0.3.4
File Size Uploaded
django_gmailapi_backend-0.3.4.tar.gz 12.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-gmailapi-backend 0.3.4
File Interpreter ABI Platform
django_gmailapi_backend-0.3.4-py3-none-any.whl Python 3 none any Details

Total release size: 25.0 kB

Release files / django_gmailapi_backend-0.3.4.tar.gz

Download URL django_gmailapi_backend-0.3.4.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
90f513a62080fc59c538d4fbcc3dffb4853b2c77a78e36a95faad146229022fc
BLAKE2b-256 checksum
How to use checksums
435980d034c9588085068f573f6c0527c6215a30ffa64a1efb22351c294a42ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Release files / django_gmailapi_backend-0.3.4-py3-none-any.whl

Download URL django_gmailapi_backend-0.3.4-py3-none-any.whl
Size 12.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5f73f85c58ddc757f89dd6adff1daaf5292c5033337738ae29c338639cdf2072
BLAKE2b-256 checksum
How to use checksums
2135585925225a7a89f8c09e68bdab60262d272d01c7da8d8080a6e0dadabf0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Release history Release notifications | RSS feed

This release

0.3.4 This release

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page