I'm having issues in sending a confirmation email, on the registration process of my flask app. A SMTPAuthenticationError appears on my terminal whenever a registering user tries to send/resend a confirmation email.
The debugger recommended to follow a link at google support, so I did. I configured my email accordingly as shown:
- IMAP: enabled
- Access to less secure apps: ON
And it works! I was able to receive a confirmation email on my gmail account inbox by directly inputting my gmail username and password, on the 2nd argument of MAIL_USERNAME and MAIL_PASSWORD respectively, as shown below:
config.py
MAIL_USERNAME = os.environ.get('MAIL_USERNAME', 'example@gmail.com')
MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD', 'examplepassword')
However, I need to integrate this in my application, in order that users can receive a confirmation email during their registration process on the app, so I tried to replace my direct email & password input, with the corresponding attributes from my forms module:
models.py
class RegistrationForm(FlaskForm):
email = StringField('Email', validators=[DataRequired(), Length(1, 64),
Email()])
username = StringField('Username', validators=[
DataRequired(), Length(1, 64),
Regexp('^[A-Za-z][A-Za-z0-9_.]*$', 0,
'Usernames must have only letters, numbers, dots or ''underscores')])
password = PasswordField('Password', validators=[
DataRequired(), EqualTo('password2', message='Passwords must match.')])
password2 = PasswordField('Confirm password', validators=[DataRequired()])
submit = SubmitField('Register')
config.py
MAIL_USERNAME = os.environ.get('MAIL_USERNAME', 'email')
MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD', 'password')
It did not work! so tried replacing it with:
config.py
MAIL_USERNAME = os.environ.get('MAIL_USERNAME', 'Email')
MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD', 'Password')
It still did not work!
Again, it's already proven to be working with a direct email & password input, wherein I was able to receive an email confirmation from my gmail account, and was also able to successfully confirm my account registration on my flask app.(As a whole, the code-wise functionality is in good working order!)
It appears that the narrowed-down root problem is the 2nd argument for both the MAIL_USERNAME and MAIL_PASSWORD; wherein, it seems that a very specific argument needs to be written down.
What is this specific keyword that I need to write for both my 2nd argument? In accordance to the user input in both the email StringField and PasswordField?