Skip to content Skip to sidebar Skip to footer

Django Email Sending On Heroku

Here is my properties in settings.py file: EMAIL_USE_TLS = True EMAIL_HOST = 'smtp.gmail.com' EMAIL_HOST_USER = 'infobot9@gmail.com' EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOS

Solution 1:

I urge you not to use Gmail for sending email in production. It's not designed for that, and as you've discovered there are measures in place to prevent it from being used as a spam relay. Even if you're sending legitimate email, Gmail is going to make things difficult for you.

Instead, use a service that's designed to send mail from hosted applications like SendGrid or Mailgun. These are both listed among Heroku's addons and both have free starter plans. Pick one and go through its getting sarted guide. Not only will this work better with small volumes of mail, it sets you up nicely for growth.


Solution 2:


Solution 3:

If you still want to use Gmail, @Pierre Monico's answer will work. I just wanted to make an edit. After allowing less secure apps to sign in to your account and Display Unlock Capatcha you should still keep two things in mind. First be sure to be logged into your browser through the account which you are using in your app to send email so that Capatch should be unlocked for that particular account and the second thing is that Google only allows Display Unlock Capatcha for Only 10 minutes . Thus if you want to use it again and again just keep Display Unlock Capatcha page open in your browser and keep it refreshing after sometime. Also if you have 2 factor authentication enabled then these steps won't work. Those accounts have different procedure.


Solution 4:

Above mentioned answers didn't work for me. So here's how I did it. Basically, you need to configure an app password.

  1. Go to your Gmail account
  2. Security > in 'Signing in to Google' section

enter image description here

  1. Turn on 2-Step Verification

  2. Set app password

and finally, need to configure settings.py or .env file(follow's the env),

EMAIL_HOST_USER=your_email@gmail.com
EMAIL_HOST_PASSWORD=generated_app_password

Tip

Using python-decouple makes it much easier to handle .env data


Post a Comment for "Django Email Sending On Heroku"