Django SMTP Error: authentication failed: authentication failure - python

I set up django email backend following way:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# Host for sending e-mail.
EMAIL_HOST = 'mytdl.de'
# Port for sending e-mail.
EMAIL_PORT = 25
# Optional SMTP authentication information for EMAIL_HOST.
EMAIL_HOST_USER = 'me#mytdl.de'
EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD')
But sending emails with django-allauth will return following error:
(535, b'5.7.8 Error: authentication failed: authentication failure')
Testing the the settings with
telnet mytdl.de 25
or Thunderbird as email client works fine.
2.7.0 Authentication successful
But Django / SMTP stills throws that error.
Django also tries to
AUTH CRAM-MD5
and not
AUTH LOGIN
any ideas?

If your email host is gmail then you can fix it with these simple steps:
Login to your gmail account (The one you are using in your Django application for sending mails ).
Then select Account from google apps or click here.
On your control panel click on Apps with account access under Sign-in & security.
Then scroll down and enable Allow less secure apps
Also maintain your settings variables in this order:
settings.py
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'example#gmail.com'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_PORT = 587

Related

How to send mail (like noreply) with Django sendgrid

I am newbie!
I want to create a django application that sends mail. it worked well on localhost, but when I deployed it, it stopped working because the host doesn't support smtp. He suggested using sendgrid, and I'm stuck here...
views.py
error:
The error message in the image that you have attached here is showing 403 forbidden which means the server understands the request but refuses to authorize it. Check whether from email address is used when you are verifying your send address. read docs in this link https://docs.sendgrid.com/ui/sending-email/sender-verification
and check all your settings for sendgrid is correct or not.
SENDGRID_API_KEY = os.getenv('SENDGRID_API_KEY')
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = 'apikey' # this is exactly the value 'apikey'
EMAIL_HOST_PASSWORD = SENDGRID_API_KEY
EMAIL_PORT = 587
EMAIL_USE_TLS = True

How to correctly configure Django to send emails with Gmail and what are the correct settings for the Gmail account?

I would appreciate some help with setting up Gmail with a Django application.
I am trying to send send an email using gmail through Django to reset user passwords.
My settings.py SMTP configuration is:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'myemail#gmail.com'
EMAIL_HOST_PASWORD = 'mypassword'
For the password I tried using both, the actual account password and the generated 16 digit password for apps which don't support 2-step authentication. I enabled the IMAP access and access for less secure apps in my gmail settings. I am still getting this error when trying to reset the password on my Django app:
SMTPSenderRefused at /reset/
(530, b'5.7.0 Authentication Required. Learn more at\n5.7.0 https://support.google.com/mail/?p=WantAuthError s21sm6387949wmc.10 - gsmtp', 'webmaster#localhost')
Any ideas what am I doing wrong? I am not sure if this is an issue with my configuration in Django or Gmail settings. Thanks in advance.
you need to enable IMAP from gmail settings : take a look here
Step 1: Check that IMAP is turned on 1-On your computer, open Gmail.
2-In the top right, click Settings Settings and then See all
settings.
3-Click the Forwarding and POP/IMAP tab.
4-In the "IMAP access" section, select Enable IMAP.
5-Click Save Changes.
Try checking "Trusted devices" in GSuite/Gmail configuration, first time sending an email form new device needs to be approved in the configuration panel.

Error in sending email using gmail smtp in Django app

I set up everything as the Django documentation but when I test sending an email.It works but When I check my inbox I find out that I sent and revived from to the same email address.
Here is the settings.py
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp.gmail.com"
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = "myemail#gmail.com"
EMAIL_HOST_PASSWORD = "mypassword"
And the views.py
...
send_mail( 'subject', 'message', 'user#gmail.com', ['myemail#gmail.com',], fail_silently=False, )
...
But I received an email from myemail#gmail.com to me(myemail#gmail.com).
Im not sure if you did this already but if youre using gmail then you will need to do the following.
Sign in to your Google Admin console (Sign in using an administrator account)
Click Security > Less secure apps.
Select Allow users to manage their access to less secure apps.
Click Save.25
Also you should use environment variables for the email address if you are live already eg:
EMAIL_HOST_USER = os.environ.get('MY_EMAIL_USER')
EMAIL_HOST_PASSWORD = os.environ.get('MY_EMAIL_PASS')
If its all working and you are just getting the mail to the wrong address can you send on the document you followed?
In terms of you settings.py that looks fine to me.

Can not connect to smtp.gmail.com in Django

I'm trying to send email using smtp.gmail.com in Django project.
This is my email settings.
settings.py
# Email Settings
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = 'myaccount#gmail.com'
EMAIL_HOST_PASSWORD = 'mygooglepassword'
views.py
...
send_mail( "message title",
"message content",
"myaccount#gmail.com",
["myaccount#hotmail.com"],
fail_silently=False)
Whenever I try to send email, I get this error
gaierror at /contact-us/
[Errno-2] Name or service not known
I tried the followings.
I set my google account's less secure app access on.
I unchecked avast antivirus setting 'Setting->Protection->Core Shields->Mail Shield->Scan outbound emails(SMTP)'
Tried different ports in email settings. 587 and 25
Switched the ssl and tls in email settings.
But it's not sending yet. When I use 'django.core.mail.backends.console.EmailBackend' instead of 'django.core.mail.backends.smtp.EmailBackend', it prints email on console.
I double checked my gmail username and password on settings.
Please help me.
Thank you.
You may need to do some configuration on Google side.
Reference answer::
Go to your Google Account settings, find Security -> Account permissions -> Access for less secure apps, enable this option.
https://accounts.google.com/DisplayUnlockCaptcha

SMTPAuthentication error when sending confirmation email in Django

Getting the error message
SMTPAuthenticationError at /accounts/signup/teacher/ (530, b'Must
issue a STARTTLS command first')
when trying to test the signup process in my django app. What should happen is that a user who signs in should receive a confirmation email after signing up.
Here are my settings
EMAIL_BACKED = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'mail.privateemail.com'
EMAIL_PORT = 587
EMAIL_USER_TLS = True
EMAIL_HOST_USER = '***#***.com'
EMAIL_HOST_PASSWORD = '***'
I am using privateemail from namecheap to send the confirmation emails

Categories