MyCustomMailer
MyCustomMailer is a Django app to authenticate Gmails with a simple front-end flow and then used programmatically to send emails.
Prerequisites
Creating an application on console.cloud.google.com, enabling the Gmail API and getting the credentials.json
Go to this tutorial by Google https://developers.google.com/workspace/guides/create-project
Follow the steps to create an application in the cloud
Enable the Gmail API
Add as Authorized redirect URI the localhost or production link (or both). These are the two variables used in the setting.py (see step 4).
Finally download the client_secret.json and put it somewhere in your project you will need it later.
Quick start
Add “mcmailer” to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [ ... 'mcmailer', ]Include the polls URLconf in your project urls.py like this:
path('mcmailer/', include('mcmailer.urls')),Run python manage.py migrate to create the mcmailer models.
In the settings.py you must declare the following four settings:
JSON_PATH = "/my/path/to/client_secret.json" LOCAL_HOST_REDIRECT_URI = "http://localhost:8000/mcmailer/g-auth-endpoint/" PRODUCTION_REDIRECT_URI = "https://example.com/mcmailer/g-auth-endpoint/"
The JSON_PATH setting is the path that the ‘credentials.json’ will be located.
The LOCAL_HOST_REDIRECT_URI setting is one (or the only one) of the Authorized redirect URIs that you will put in your credentials in the console.cloud.google.com. This URI will be used if the DEBUG is equal to True. The URI must point to a specific view so just change the part (if needed) before the /mcmailer/g-auth-endpoint/. Example: LOCAL_HOST_REDIRECT_URI = “http://localhost:8000/mcmailer/g-auth-endpoint/”
The PRODUCTION_REDIRECT_URI setting is one (or the only one) of the Authorized redirect URIs that you will put in your credentials in the console.cloud.google.com. This URI will be used if the DEBUG is equal to False. The URI must point to a specific view so just change the part (if needed) before the /mcmailer/g-auth-endpoint/. Example: LOCAL_HOST_REDIRECT_URI = “https://example.com/mcmailer/g-auth-endpoint/”
Start the development server and visit http://127.0.0.1:8000/mcmailer/connect/ enter the email you want to to grand access to your application and click submit.
9. Now that you have successfully granted access to your application from at least one Gmail, you can send emails from that email using send_mc_email() function of the package:
from mcmailer.utils.sendgmail import send_mc_email, load_credentials
authorized_gmail_address = 'someaddress@gmail.com'
success, credentials = load_credentials(authorized_gmail_address)
send_mc_email(
credentials,
from_address=authorized_gmail_address,
to_addresses=[
'toaddress2@gmail.com',
'toaddress3@gmail.com',
'toaddress4@gmail.com'
],
from_official_name='MY OFFICIAL NAME',
subject='My Subject',
msg_plain='My Plain Email Body',
msg_html='My HTML Email Body'
)
Now any user that has Gmail can grant ‘gmail.send’ access to your app by following the authorization flow (http://127.0.0.1:8000/mcmailer/connect/) and then you will be able to send emails on behalf of them.
If your app doesn’t need to authenticate new users on production and you only need to authenticate a Gmail to sent emails programmatically then you can just authenticate your Gmail locally once and then remove the package variables from settings.py and the package’s URL path from urls.py. Just leave the ‘mcmailer’ in your INSTALLED_APPS to be able to send emails programmatically.
Metadata
Release files for django-mcmailer 1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-mcmailer-1.1.tar.gz | 10.7 kB | Without provenance | Details for django-mcmailer-1.1.tar.gz |
Release files / django-mcmailer-1.1.tar.gz
| Download URL | django-mcmailer-1.1.tar.gz |
|---|---|
| Size | 10.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b555e0379d258de13ca8697a74fa5a8c02152d03f104f94071e0cca390ee2730
|
|
BLAKE2b-256 checksum How to use checksums |
9630812b0bdc8bbd07daaf561d48f91c1daecdbf0f46901c20c820ed3c4bb03a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.3
|
Security for django-mcmailer 1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.