sabuhish / fastapi-mail

Fastapi mail system sending mails(individual, bulk) attachments(individual, bulk)
https://sabuhish.github.io/fastapi-mail/
MIT License
698 stars 81 forks source link

[Question] Gmail "MAIL_USERNAME" ConnectionConfig #28

Closed ihsanmohamad closed 3 years ago

ihsanmohamad commented 3 years ago

How do i use gmail alias with "MAIL_USERNAME"? Using gmail, i keep getting bad credential error.

What i'm trying to achieve is SportJom sportjom@gmail.com

but that was not possible if my "MAIL_USERNAME" is not the email address.

For "MAIL_USERNAME" I have to use my full email address as the username. Is this just gmail issue?

sabuhish commented 3 years ago

use SportJom in MAIL_FROM_NAME attribute and MAIL_USERNAME sportjom@gmail.com

ihsanmohamad commented 3 years ago

use SportJom in MAIL_FROM_NAME attribute and MAIL_USERNAME sportjom@gmail.com

thank you for that, I just realised that I have MAIL_FROM_NAME option in the new version. However it seems like I need to have both MAIL_FROM and MAIL_FROM_NAME, else it would throw pydantic error "MAIL_FROM field required".

mail

The second email is the one that I received using fastapi-mail, while the first one received from me manually sending the email.

sabuhish commented 3 years ago

Yes exactly, we discussed this at #16 It is available as new feeature. you are required to provide MAIL_FROM as well.

ihsanmohamad commented 3 years ago

Hi yes, I did that and the result is like from the image from my previous reply with the second email. How do I achieve the result like the first email?

Here is how I setup my config mail2

My current setting will also include my email. I would like to get result like this SportJom <sportjom.my@g mail.com>

Thank you and sorry for the inconveniences!

Turall commented 3 years ago

Hi yes, I did that and the result is like from the image from my previous reply with the second email. How do I achieve the result like the first email?

Here is how I setup my config mail2

My current setting will also include my email. I would like to get result like this SportJom <sportjom.my@g mail.com>

Thank you and sorry for the inconveniences!

Hi @ihsanmohamad, thank you for using fastapi-mail. I tested your method and it worked. Here is how I setup my config: gmail

and I got the email as you wanted: email Can you explain the situation in more detail?

Turall commented 3 years ago

use SportJom in MAIL_FROM_NAME attribute and MAIL_USERNAME sportjom@gmail.com

thank you for that, I just realised that I have MAIL_FROM_NAME option in the new version. However it seems like I need to have both MAIL_FROM and MAIL_FROM_NAME, else it would throw pydantic error "MAIL_FROM field required".

mail

The second email is the one that I received using fastapi-mail, while the first one received from me manually sending the email.

but if you want to receive an email and the sender's name then you can correct the config when you send an email

here is an example: new_gmail

and the result is: new_email

ihsanmohamad commented 3 years ago

Oh my god, I felt stupid and embarrassed. Turns out it was my windows mail having that result. On my gmail opened from web, it works as expected. Even though I just knew about MAIL_FROM_NAME new attribute in the latest release (i was using release 0.2.8.5), I can't believe it was such a stupid mistake coming from the windows mail.

Sorry for the trouble, thank you so much for providing assistance to me. Much appreciated.

Turall commented 3 years ago

Happy to see you resolved the issue. Thing happens, it is okay :) at least you figured out the problem

rextech03 commented 2 years ago

I have been struggling with send email using this module but even after enabling "LESS SECURE APP" on my gmail account I always get this error: fastapi_mail.errors.ConnectionErrors: Exception raised Error connecting to smtp.gmail.com on port 587: [Errno 10061] Connect call failed ('74.125.140.109', 587), check your credentials or email service configuration. I have checked my login detail but all to no avail Capture ` message = MessageSchema( subject="EasyShopas Account Verification Mail", recipients=email, # List of recipients, as many as you can pass body=template, subtype="html" )

fm = FastMail(conf)
await fm.send_message(message) 

Capture1 `

Carlos-err406 commented 1 year ago

im having an issue similar to @rextech03 's Exception raised (535, '5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials 78-20020a250d51000000b00b7767ca7487sm181675ybn.36 - gsmtp'), check your credentials or email service configuration

using this configuration, that has worked for some photo_2023-03-23_22-47-20

Carlos-err406 commented 1 year ago

im having an issue similar to @rextech03 's Exception raised (535, '5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials 78-20020a250d51000000b00b7767ca7487sm181675ybn.36 - gsmtp'), check your credentials or email service configuration

using this configuration, that has worked for some photo_2023-03-23_22-47-20

sorry i just noticed this isn't actually a problem with fastapi-mail is just that Google security is very tight regarding access from 3rd party apps , just tried with a different mail server and worked like a charm