How to send emails through Django using your own domain name with Google Workspace?

Okba Boularaoui
2 min readMar 16, 2021

There are many people who want to send emails like ‘support@site.com’ or ‘no-reply@website.com’. But there are few sources that explain how to make the necessary settings to do so, especially with Django Framework.
So I made this explanation for a simple reference for devs.

Initialize Google Workspace account

Make an account with Google Workspace here :

https://workspace.google.com/

It will give you 14 days trial for free then you can use ‘Business Starter’ plan for 4,68 € / Month.

Now access to your account using Google Admin Console :

https://admin.google.com/

set your MX Records in your domain provider or your server using this configurations:

https://support.google.com/a/answer/140034

MX Records

In User section, create emails for your needs, for example:

support@yourdomain.com

GMAIL SMTP Configurations

Now Go to Apps > Google Workspace > Gmail > Routing (Routing is not the same Default Routing)

or directly click on this url : https://admin.google.com/ac/apps/gmail/routing

Scroll down to “SMTP relay service”

Then Setup your configuration, as basic settings, set:

- Description (write any description for easy identifying this configurations later)
- Only addresses in my domains
- Require SMTP Authentication
- Require TLS encryption (We will talk about this later)

Now you have to turn on “Less Secure Apps” to allow your app to sent emails

access to this url: https://myaccount.google.com/lesssecureapps.

Now switch to ‘Allow less secure apps: OFF’

Django Configurations

in this step we will set the configurations for a Django project, but it’s the same configurations for any SMTP server.

in settings.py :

EMAIL_BACKEND = ‘django.core.mail.backends.smtp.EmailBackend’
EMAIL_HOST = ‘smtp-relay.gmail.com’
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = ‘username@yourdomain.com’
EMAIL_HOST_PASSWORD = ‘Your Password Here’

do you remember ‘ Require TLS encryption’ in step above ? If you want to not using TLS encryption, then use port 25, port 465 or even 587 may work, and make EMAIL_USE_TLS = False.

! Note: It’s better if you store the password in .env file

That’s it, now you are able to send emails using your domain name.

if you have any issues you can check this urls :

* https://support.google.com/a/answer/2956491?hl=en#zippy=
* https://support.google.com/mail/answer/7126229#zippy=%2Ci-cant-sign-in-to-my-email-client

--

--