Skip to content

A email backend for django for sending emails with gsuite service account

License

Notifications You must be signed in to change notification settings

thomasgubler/django-gsuite-email

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GSuite Email Backend

Downloads GitHub release (latest by date) GitHub issues Documentation Status

This package allows to use Django's send_mail command to send emails through GSuite account.

It requires a serviceaccount credential created in Google coud console, The crendential file need to have https://www.googleapis.com/auth/gmail.send scope.

Follow this tutorial to create the credentials file, make sure to add https://www.googleapis.com/auth/gmail.send scope.

Installation

pip install django-gsuite-email

Quick start

1. Add it to installed apps in setings.py

INSTALLED_APPS = [
    ...
    'django_gsuite_email',
    ...
]

2. Set the Email EMAIL_BACKEND setting

EMAIL_BACKEND = 'django_gsuite_email.GSuiteEmailBackend'

3. Set location of credentials file.

To do this, either set GSUITE_CREDENTIALS_FILE environment variable.
OR
set GSUITE_CREDENTIALS_FILE in settings.py

GSUITE_CREDENTIALS_FILE="/path/to/credentials/file.json"

Note: GSUITE_CREDENTIALS_FILE in settings.py will take precedence over environment variable.

Alternatively you can set the JSON string in a env variable and initialize GSUITE_CREDENTIALS_JSON in settings.py

from decouple import config
GSUITE_CREDENTIALS_JSON = config("GSUITE_CREDENTIALS_JSON")

If this is set it will take precedence over GSUITE_CREDENTIALS_FILE

4. Send emails

from django.core.mail import send_mail

send_mail(
    'Subject here',
    'Here is the message.',
    '[email protected]',
    ['[email protected]'],
    fail_silently=False,
)

About

A email backend for django for sending emails with gsuite service account

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%