Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fastapi_mail.errors.ConnectionErrors on gmail smtp #113

Closed
pepegc opened this issue Mar 27, 2022 · 6 comments
Closed

fastapi_mail.errors.ConnectionErrors on gmail smtp #113

pepegc opened this issue Mar 27, 2022 · 6 comments

Comments

@pepegc
Copy link

pepegc commented Mar 27, 2022

I am getting the following error when trying the first basic example here:

fastapi_mail.errors.ConnectionErrors: Exception raised (535, '5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials l33-20020a0568302b2100b005cdad9100desm5879477otv.40 - gsmtp'), check your credentials or email service configuration

MAIL_USERNAME=asd
MAIL_PASSWORD=<16-digit app password generated in gmail admin, 2step verification enabled>
MAIL_FROM=<matching email>
MAIL_PORT=587
MAIL_SERVER=smtp.gmail.com
MAILFROM_NAME=asd
MAIL_TLS=1
MAIL_SSL=0
USE_CREDENTIALS=1
VALIDATE_CERTS=1

I tried with personal mail/pwd for testing and didn't work. Then I tried with validated mail/pwd currently being used in production on another (flask) app and it didn't work.

@pepegc
Copy link
Author

pepegc commented Mar 27, 2022

Ok I'm pretty sure it's because the api in local host is not secure enough for Google (no https). Is there a way to run the app with uvicorn with a https flag or something? For a second I thought adding HTTPSRedirectMiddleware would help but that's just throwing me warnings and errors.

WARNING:  Invalid HTTP request received.
[...]
h11._util.RemoteProtocolError: illegal request line

@filipagh
Copy link

filipagh commented Apr 2, 2022

Ok I'm pretty sure it's because the api in local host is not secure enough for Google (no https). Is there a way to run the app with uvicorn with a https flag or something? For a second I thought adding HTTPSRedirectMiddleware would help but that's just throwing me warnings and errors.

WARNING:  Invalid HTTP request received.
[...]
h11._util.RemoteProtocolError: illegal request line

i do not think thats problem, we do not have problem send mails when run locally with http, but one our developer has same problem on her network, when she try mobile net then it works, so look like you have some firewall block on router or something, maybe it helps

@pepegc
Copy link
Author

pepegc commented Apr 2, 2022

It's fixed now but maybe you can explain why because I'm not sure and just continued working on something else: the problem was the value I had for MAIL_USERNAME. Turns out it started working when I set MAIL_USERNAME to be the sender email, which wasn't obvious because the email was already set in MAIL_FROM. So basically it works when MAIL_USERNAME = MAIL_FROM = my_email@gmail.com

@filipagh
Copy link

filipagh commented Apr 2, 2022

we have same value for MAIL_USERNAME and MAIL_FROM but same result on her network soo but she cant access some others pages also ..

about MAIL_FROM i think it do not need to be same, but you need "access" to that mail from smtp acc,
in gmail i can add mail alias like (my personal mail) and then change MAIL_FROM to my mail
then all mail are send with smtp acc but with my mail as from

@sabuhish
Copy link
Owner

sabuhish commented Apr 17, 2022

Hi there!
Locally should everything work fine, being said that you don't need to run your application with a TLS certificate unless your mail configuration requires it and you may have to set it while establishing connection.
MAIL_FROM_NAME parameter is used to specify upon receiving the email to show from whom you have received the email.
MAIL_USERNAME is the one that needs to be specified for establishing connections. You have to set this parameter.
MAIL_FROM has been set, because some email providers use different sender email addresses, this param is not used for connection at all but MAIL_USERNAME does do that.

@sabuhish
Copy link
Owner

I think we are all good with finding and resolving the issue, I will kindly close the issue if you face another issue feel free to open it. And thanks @filipagh for your help also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants