Sending email with Django using Gmail not working - django

I'm new to Django and I want to send the email through my Django server using my Gmail account but unfortunately, I'm getting an error while sending emails even though I've put all credentials correctly there is one thing more in my Gmail account which is "less secure apps" that has to be enabled but this feature is no longer available in Gmail so now how can I send the emails in Django?
error while sending the email
b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials f14-20020a05600c4e8e00b0039c5642e430sm4688852wmq.20 - gsmtp'

Since May 30 2022 the less secure apps feature has been disabled. Now, to let 3rd party apps access gmail you must generate an App password and to generate an app password you must first enable 2-factor authentication for your account:
https://myaccount.google.com/apppasswords
Once you have the app password you can simply replace your host account password with the app password:
EMAIL_HOST_PASSWORD = '<app_password>'
You can find the complete email integration process wonderfully explained here: https://github.com/CoreyMSchafer/code_snippets/tree/master/Django_Blog/12-Password-Reset/django_project

im looking forward for an answer too, as i am experiencing the same problem.
In the meantime, i had to change the email provider to another company, for me it worked with mailjet, they have a free plan and no card info needed, hope this helps you!

Related

Problem with sending email in django using SMTP with new google rules

I am using smtp to send emails in django app but for some reasons it stops working and i found this on the google page.
I do not want to use SendGrid or others.because in my app i send more than 1000000 emails per semester and it was working well before this new condition.
How can i solve this problem ? Thanks.
Try to create an application token in the Google account you use to send the emails with and use it instead of your usual email password.
Have a look at this link: Authorizing Your App with Gmail

Convenient and simple solution to receive and answer emails in a small Django app

I am developing a Django app which uses Email in some of its components (but not at its core). I am looking for a simple and cheap solution that satisfies the following requirements:
Only the custom domain of the app is used (no username#gmail address)
Django can send emails programmatically (error reporting, user data from forms)
The admin can receive and and answer mails through an email client of their choice
The provider should allow sending mass emails (not a priority)
The solution does not need to be free
Solutions I have considered so far:
Using my hosting provider: They understandably don't support custom email accounts for VPS customers
Amazon SES: would work for sending email, but received emails would land in a S3 bucket; it is unclear to me how to connect this to an email client
Sendgrid: would work for sending email, but the only way to handle inbound mail is to forward it as HTTP POST request to a view
Django extensions to read and send email through the admin interface: I can't use my email client
Google Workspace: seems like this could work. My issue is that it includes a lot of functionality I don't really need. Does anyone have experience with this?
All I really need is to alias a standard email account to my custom domain.
You can create your custom domain email account with any provider that supports SMTP clients (including Google Wspace) and configure the SMTP credentials into Django's email backend (or use a fancier email package, like for exmaple Django-Anymail).
in settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.email_provider_server.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'email_account_user_name'
EMAIL_HOST_PASSWORD = 'secret_password'
EMAIL_USE_TLS = True
Receive emails and reply through the provider's webmail or configure IMAP/SMTP in a desktop client like Outlook/Thunderbird/WindowsMail etc.
The provider will give you the IMAP/SMTP settings. Best practice is to feed the password into Django's settings.py through environment variables etc. for security.

Using sendgrid domain authentication sends email to spam in Django

I am trying to send email from my Django application. For this, I have used Twilio SendGrid service. Though my application can send the email, it ends up in spam folder. So, I have followed this tutorial to authenticate my domain which I bought from AWS route 53. In sendgrid, the domain authentication status shows 'verified' but the emails are still sent to spam folder. I have not created any MX or TXT record in DNS setting as the tutorial says it was created automatically during domain authentication in sendgrid.
One thing I have noticed that the email still shows, 'via.sendgrid.net' message (attached an image below) with the email. Whereas it should be my authenticated domain name. I have created sendgrid account with an outlook email and using that address to send email from Django app. Is this the reason my emails are going to spam? Or can anyone please help me to find a solution for this problem? Thanks in advance.
FYI: I have done 'Single Sender Verification' in sendgrid during developing this app. But now I have deployed it in aws. I guess this feature is still working instead of 'Domain Authentication'.

Email send using app password - Username and Password not accepted?

I can't figure out why I can't send email in Django.
I've enabled 2-step verification and generated App Password for this connection.
But Gmail smtp returns:
SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials q29sm16257362qtc.10 - gsmtp')
I thought that using App Password will not cause such errors.
EDIT:
The email uses a custom domain but I guess this is not a problem. I think that smtp.gmail.com should work.
I haven't allowed less secured apps since I think it is not needed with App Password.
I had the same problem with two-factor authentication and allowed less secured apps. It is necessary to use App password ! there is still one last feature to activate: https://accounts.google.com/DisplayUnlockCaptcha
If you have a Gsuite domain click on this link : https://admin.google.com/ac/security/lsa and "Allow users to manage their access to less secure applications"

discourse can't send email

i installed a discourse on AWS bitnami edu3d.co. I did the following things but still can't send the login verification email.
config the discourse by this instruction https://docs.bitnami.com/bch/apps/discourse/configuration/configure-smtp/
in AWS, request email sending limits
in AWS, verify my email identity,
in AWS, send test email (it is correct)
create my credential
checked spam boxes (no email)
Thank you!
The problem is solved. I guess problem is that I set the username and password wrongly.
smtp_address = ''
smtp_port = 587
smtp_domain = 'edu3d.co'
smtp_user_name = ''
smtp_password = ''
smtp_enable_start_tls = true
smtp_authentication = login
If you have problem in setting smtp for the discourse installed on AWS EC2 bitnami. You can do the following checks.
1) check whether your VM instance can connect the smtp server (test if smtp_address and smtp_port are correct)
I found 25 is not responding and 465 sometimes broke too, 587 works well.
2) check whether your username and password set correctly.
AWS provides this instruction https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email-smtp-client-command-line.html
How I find the problem
I really can't figure out why the smtp setting is 'correct' but i just can't receive the email. So I changed to gmail, the setting is a bit easier than AWS SES. After change, I received the email immediately but it says the login method is not secure so Google blocked it. This proves the smtp setting is working. And according to previous test, my VM instance can connect to the smtp server. So there should have something wrong in the smtp setting.
I go to AWS SES, intending to check the my credential. But I can only create a new one. So I did, then I found I misunderstood the username and password. After change, the email is working. Great!
The following instruction is very helpful!
https://docs.bitnami.com/bch/apps/discourse/configuration/configure-smtp/