Skip to main content

Send emails via a GSuite Service-account.

Project description

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"
GSUITE_USER_FROM_EMAIL = False  # use the user of from_email if True. Default value False.
GMAIL_USER = 'user@domain'      # default user if GSUITE_USER_FROM_EMAIL is not True. Default value None.
GMAIL_SCOPES = ['https://www.googleapis.com/auth/gmail.send', ... ] # Default value ['https://www.googleapis.com/auth/gmail.send', ]

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

4. Send emails

from django.core.mail import send_mail

send_mail(
    'Subject here',
    'Here is the message.',
    'from@example.com',
    ['to@example.com'],
    fail_silently=False,
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

djau_gsuite_email-0.1.5.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

djau_gsuite_email-0.1.5-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file djau_gsuite_email-0.1.5.tar.gz.

File metadata

  • Download URL: djau_gsuite_email-0.1.5.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for djau_gsuite_email-0.1.5.tar.gz
Algorithm Hash digest
SHA256 d8d18d76f48ea9a470cbb16a236697c23cfbb7fff9a4d8b2ba0201876e31d4c4
MD5 528fa10bebce79d29abeb64b7ecad7aa
BLAKE2b-256 47d9540139d93c93145eebd3b166091a6c127be26fc71847baf82677cb401b4a

See more details on using hashes here.

File details

Details for the file djau_gsuite_email-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for djau_gsuite_email-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a5875b4188f94ab0c968a8588b91d9cdf60aabffb5a3df05d6e9bc4094c5e5ed
MD5 013e60abbffc4c35b36ff8c0673d3964
BLAKE2b-256 3ced46b4f71549553048a09f3f4db64d1df3f93379e6420cbf57a5493696d728

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page