Let's change email-server to Gmail

I have used an external email-server for my forms in Django. Let's change that to Gmail, since Gandi has started to want more money for using theirs.

Requirements

A working Django project with email-functionality

Implementation

I grabbed the setting needed in a post by AbstractAPI(1):

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'your_username@gmail.com'
EMAIL_HOST_PASSWORD = 'your_created_password'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False

Next you'll need to do is to setup less secure access for Gmail.

Login to your account in Google and go to 2-step verification settings, and create a new token.

You should name the token the same that your Django app is.

After that you can try it out. Remember to not save unencrypted credentials anywhere!

You should also change the perceived sender of the email in your views.py. More on the subject here on my article: Django comment on every page.

Source(s)

  1. https://www.abstractapi.com/guides/django-send-email

All articles


Comments

No published comments yet.


Add a Comment

Your comment is held for review before it appears publicly.

Your email is never published or shared.

Up to 2,000 characters.

Tick the box, then click Submit right away (Google expires the check after about two minutes).