Django-gmailapi-json-backend - Email backend for Django which sends email via the Gmail API through a JSON credential

Overview

django-gmailapi-json-backend

Email backend for Django which sends email via the Gmail API through a JSON credential

The simple SMTP protocol is disabled by default for Gmail users, since this is included in the Less Secure Apps (LSA) category. This package implements the Gmail API directly with a JSON Google service account as a Django email backend and can be used with 'django-mailer'.

Requirements

Python 3.9+

Installation

The package is available through pip. To easily install or upgrade it, do

pip install --upgrade django-gmailapi-json-backend

Configuration

In your settings.py:

  1. Add the module into the INSTALLED_APPS
    INSTALLED_APPS = [
        ...
        'django-gmailapi-json-backend',
        ...
    ]
  2. Set the email backend
    EMAIL_FROM = '[email protected]'
    EMAIL_BACKEND = "gmailapi_backend.service.GmailApiBackend"
    GMAIL_SCOPES = ['https://www.googleapis.com/auth/gmail.send']
    GOOGLE_SERVICE_ACCOUNT = '{
         "type": "service_account",
         "project_id": "your-project",
         "private_key_id": 
         ...
    }'
    If you use django-mailer as email backend you can send through gmail API as follow:
    EMAIL_BACKEND = "mailer.backend.DbBackend"
    MAILER_EMAIL_BACKEND = "gmailapi_backend.service.GmailApiBackend"

How to create the Google service account

  1. Create a project on the developer console at https://console.cloud.google.com (it must be a Google Workspace account, not a simple gmail account)
  2. Enable the gmail api from the library menu
  3. On API and services > Credentials, create a new service account as a JSON you should use for GOOGLE_SERVICE_ACCOUNT
  4. Copy your client id from the menu IAM and administration > service account. Click on the service you have just created, find the unique id and copy it.
  5. Move to the administrator console at https://admin.google.com/ and choose your user (i.e. EMAIL_FROM)
  6. Go to Security > Data access and control > API controls > Delegation at domain level and add a new one with your client id and the services you need like https://www.googleapis.com/auth/gmail.send to send email through API.

Usage

Use the native EmailMessage class in Django. Just a sample:

message = render_to_string('email/ordine_pagato.html', {
  'ordine': ordine,
})
mail_subject = _('This is just a sample')
email = EmailMessage(
  mail_subject, message, settings.EMAIL_FROM, to=['[email protected]']
)
email.content_subtype = "html"
email.attach(sample_file.file.name, sample_file.file.read(), 'application/pdf')
email.send()
Owner
Innove
Innove
🗂️ 🔍 Geospatial Data Management and Search API - Django Apps

Geospatial Data API in Django Resonant GeoData (RGD) is a series of Django applications well suited for cataloging and searching annotated geospatial

Resonant GeoData 53 Nov 01, 2022
Full control of form rendering in the templates.

django-floppyforms Full control of form rendering in the templates. Authors: Gregor Müllegger and many many contributors Original creator: Bruno Renié

Jazzband 811 Dec 01, 2022
Django friendly finite state machine support

Django friendly finite state machine support django-fsm adds simple declarative state management for django models. If you need parallel task executio

Viewflow 2.1k Dec 31, 2022
Official clone of the Subversion repository.

Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. All documentation is in the "docs" directo

Raymond Penners 3 May 06, 2022
Django-powered application about blockchain (bitcoin)

Django-powered application about blockchain (bitcoin)

Igor Izvekov 0 Jun 23, 2022
webfest Django project @innovaccer

inno-doctor webfest Django project @innovaccer setup guide create new directory for project clone the repo with url into the directory make sure pytho

Rohit sahu 6 Oct 28, 2022
Py-instant-search-redis - Source code example for how to build an instant search with redis in python

py-instant-search-redis Source code example for how to build an instant search (

Giap Le 4 Feb 17, 2022
A Redis cache backend for django

Redis Django Cache Backend A Redis cache backend for Django Docs can be found at http://django-redis-cache.readthedocs.org/en/latest/. Changelog 3.0.0

Sean Bleier 1k Dec 15, 2022
This website serves as an online database (hosted via SQLLite) for fictional businesses in the area to store contact information (name, email, phone number, etc.) for fictional customers.

Django-Online-Business-Database-Project this project is still in progress Overview of Website This website serves as an online database (hosted via SQ

1 Oct 30, 2021
A Django app that allows visitors to interact with your site as a guest user without requiring registration.

django-guest-user A Django app that allows visitors to interact with your site as a guest user without requiring registration. Largely inspired by dja

Julian Wachholz 21 Dec 17, 2022
Stream Framework is a Python library, which allows you to build news feed, activity streams and notification systems using Cassandra and/or Redis. The authors of Stream-Framework also provide a cloud service for feed technology:

Stream Framework Activity Streams & Newsfeeds Stream Framework is a Python library which allows you to build activity streams & newsfeeds using Cassan

Thierry Schellenbach 4.7k Jan 02, 2023
Official Python agent for the Elastic APM

elastic-apm -- Elastic APM agent for Python This is the official Python module for Elastic APM. It provides full out-of-the-box support for many of th

elastic 369 Jan 05, 2023
pdm-django: Django command shortcuts for PDM

pdm-django: Django command shortcuts for PDM A plugin that gives you command shortcuts for developing with PDM. pdm run python manage.py runserver -

Neutron Sync 2 Aug 11, 2022
Bringing together django, django rest framework, and htmx

This is Just an Idea There is no code, this README just represents an idea for a minimal library that, as of now, does not exist. django-htmx-rest A l

Jack DeVries 5 Nov 24, 2022
Django CRUD REST API Generator

Django CRUD REST API Generator This is a simple tool that generates a Django REST API with the given models. Specs: Authentication, DRF generic views,

Mehmet Alp Sümer 57 Nov 24, 2022
Imparare Django ricreando un sito facsimile a quello Flask

SitoPBG-Django Imparare Django ricreando un sito facsimile a quello Flask Note di utilizzo Necessita la valorizzazione delle seguenti variabili di amb

Mario Nardi 1 Dec 08, 2021
Resolve form field arguments dynamically when a form is instantiated

django-forms-dynamic Resolve form field arguments dynamically when a form is instantiated, not when it's declared. Tested against Django 2.2, 3.2 and

DabApps 108 Jan 03, 2023
Plug and play continuous integration with django and jenkins

django-jenkins Plug and play continuous integration with Django and Jenkins Installation From PyPI: $ pip install django-jenkins Or by downloading th

Mikhail Podgurskiy 941 Oct 22, 2022
A starter template for building a backend with Django and django-rest-framework using docker with PostgreSQL as the primary DB.

Django-Rest-Template! This is a basic starter template for a backend project with Django as the server and PostgreSQL as the database. About the templ

Akshat Sharma 11 Dec 06, 2022
Highlight the keywords of a page if a visitor is coming from a search engine.

Django-SEKH Django Search Engine Keywords Highlighter, is a middleware for Django providing the capacities to highlight the user's search keywords if

Julien Fache 24 Oct 08, 2021