3

I see many solutions but still, I have a problem for send mail and I also set email and password to ~/.bash_profile so please help me.

Here my connfig.py file code

import os

class Config:
    SECRET_KEY=os.environ.get('SECRET_KEY')
    SQLALCHEMY_DATABASE_URI=os.environ.get('SQLALCHEMY_DATABASE_URI')
    MAIL_SERVER = 'smtp.googlemail.com'
    MAIL_PORT = 465
    MAIL_USE_SSL= True  
    MAIL_USERNAME=os.environ.get('EMAIL_USER')
    MAIL_PASSWORD=os.environ.get('EMAIL_PASS')

I also try the google two-step verification and app password still I have a problem. What can I do now?

Malav Mevada
  • 178
  • 11

1 Answers1

2

I had the same problem when I debugged my code I found that my os.environ.get('EMAIL_USER') was empty. Make sure it has your exact credentials.

What I did was hardcoding my username and password (it is not recommended to do it for security purposes) :

class Config:

    SECRET_KEY=os.environ.get('SECRET_KEY')
    SQLALCHEMY_DATABASE_URI=os.environ.get('SQLALCHEMY_DATABASE_URI')
    MAIL_SERVER = 'smtp.googlemail.com'
    MAIL_PORT = 465
    MAIL_USE_SSL= True  
    MAIL_USERNAME='youremailhere'
    MAIL_PASSWORD='yourpasswordemailhere'

... and then make sure you have the Less Secure App Access turned on in your google account, you'll find it here -> https://myaccount.google.com/lesssecureapps

Ivan Aracki
  • 4,861
  • 11
  • 59
  • 73
Fady Ayoub
  • 391
  • 2
  • 11
  • Yeah, after changing the environment variable. I need to restart my VScode and then it's working properly. I hope this helps. – Malav Mevada Apr 30 '21 at 14:41