Django Reset PW emails not sending on AWS - python

Difficult to phrase this question and what I've done as I don't know where the error is occuring.
I'm using Django hosted on AWS Elastic Beanstalk and SES to send emails. (Only for password reset) However the password reset emails don't seem to be sending.
When I try to send an email as below however it works.
send_mail('Test', 'Email content', 'email#email.com',['email#email.com',])
Also locally the password reset email sends (its put in spam but that's a different issue)
My email settings are:
EMAIL_HOST = 'smtp.gmail.com' # mail service smtp
EMAIL_HOST_USER = 'email#email.com' # email id
EMAIL_HOST_PASSWORD = '****' #password
EMAIL_PORT = 587
# EMAIL_USE_TLS = True
EMAIL_BACKEND = 'django_ses.SESBackend'
AWS_ACCESS_KEY_ID = 'ACCESSKEY'
AWS_SECRET_ACCESS_KEY = 'SECRETKEY'
AWS_SES_REGION_NAME = 'eu-west-1'
AWS_SES_REGION_ENDPOINT = 'email.eu-west-1.amazonaws.com'
DEFAULT_FROM_EMAIL= 'email#email.com'
If it's relevant, anywhere I've written email#email.com is actually the same email.
Any help would be much appreciated.
Thanks

Related

Sending Emails through Django is not working in Nov 2022

I have tried all the advice and guides already available but it is not working at any cost. Please refer below to know more.
Activated the 2-factor authentification required.
2-factor authentication activated
I generated the App password and used it correctly in the Django settings.py file. You can see there is an app password in the above image.
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp.gmail.com"
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = "xyz"
EMAIL_HOST_PASSWORD = "abc"`
And use the following code to send the email.
subject = "Email verification"
text = "Hi, This is the link to verify you registration email with our site {0}. Please paste the link to verify your account {0}/auth/verify/{1}/"
message = text.format(self.request.get_host(), self.token)
email_from = settings.EMAIL_HOST_USER
recipient_list = [self.request.data['email'],]
send_mail(subject, message, email_from, recipient_list)`
But still, I am getting the below error.
Error form smtp: smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials l9-20020a17090a150900b0020d48bc6661sm10003685pja.31 - gsmtp')
I have tried enabling less secure apps but it shows like this:
No change possible for less secure apps
I have also tried this link: https://accounts.google.com/DisplayUnlockCaptcha
enter image description here

How to send Email in Django using office365

I am working in a project where I need to send the email to the user who is filling the Email in the form. I am able to send email by using my Gmail Account details but while using outlook.365. This is the image with error that I am getting.
My requirement is :
Once users come in the registration form and fill the details as Name, Email, Mobile
Whatever Email is put there in the form, send the email with link to create new password.
Here is my code:
settings.py:
# Using outlook365:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST_USER = 'support#academic.com'
EMAIL_HOST = 'smtp.outlook.office365.com' # (also tried : smtp.office365.com and
outlook.office365.com)
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_PASSWORD = 'My_Password'
# Using my gmail account:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST_USER = 'admin#gmail.com'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_PASSWORD = 'My_Password'
views.py:
subject = "Academic - Create New Password"
message = "Hi %s! Please create your new Password here : http://127.0.0.1:8000/api/create-password" % firstname
send_mail(
subject, # Subject of the email
message, # Body or Message of the email
'support#academic.com', # from#gmail.com (admin#gmail.com for gmail account)
[email], # to#gmail.com # email that is filled in the form
)
Please guide me that what extra setting or configuration I need to send email using Outlook365.
Please put this in settings.py file.
SERVER_EMAIL = EMAIL_HOST_USER
Your settings look correct. Use EMAIL_HOST = "smtp.office365.com". Verify that you are using the correct credentials. Check that your outlook account is set up properly to send emails from support#academic.com.

How to sending email with django using gmail

I am trying sending email for password reset but it giving me following error.
SMTPSenderRefused at /account/password_reset/ (530, b'5.7.0 Must issue
a STARTTLS command first. x20sm7511321wme.6 - gsmtp',
'webmaster#localhost')......
here is my code.
EMAIL_USE_TSL = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'user#gmail.com'
EMAIL_PASSWORD = '*******'
EMAIL_PORT = 587
There's a typo. You wrote EMAIL_USE_TSL instead of EMAIL_USE_TLS.

Django and AWS Simple Email Service [duplicate]

This question already has answers here:
Amazon SES SMTP with Django
(8 answers)
Closed 10 months ago.
I'm attempting to get a django site up and running and I'm trying to enable django's standard password reset service.
My site is hosted by AWS EC2, so I figured I would use AWS SES for my email service. However, I can't get the smtp connection to work. Any idea on how to solve for the following error:
Exception Type: SMTPSenderRefused
Exception Value: (530, b'Authentication required', 'example#example.com')
I've looked at the following, but I'd prefer to stay with django's built-in email back-ends if possible:
https://github.com/django-ses/django-ses
https://github.com/azavea/django-amazon-ses
Amazon SES SMTP with Django
Email Settings:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'email-smtp.us-west-2.amazonaws.com'
EMAIL_PORT = 587 # (I've also tried 25, 465, & 2587)
EMAIL_HOST_USER = ''
EMAIL_PASSWORD = ''
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'example#example.com' # but my real email address
My EMAIL_HOST_USER and EMAIL_PASSWORD are set to my SMTP credentials I obtained by following the instructions at: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-credentials.html
Also, I was sure to verify my DEFAULT_FROM_EMAIL and my domain following these instructions: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/verify-addresses-and-domains.html
And DKIM is enabled and my nameservers have been updated.
Any help would really be appreciated.
UPDATE:
I was able to get the django email send working with the django-ses 3rd party library, but I'm still not able to figure out why the standard backend doesn't work via SMTP.
I think there is definitely something wrong with my code as I went so far as to switch email clients from AWS SES to Zoho mail and I'm still receiving the same 530 Authentication required error.
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.zoho.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'support#example.com'
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'support#example.com'
EMAIL_PASSWORD = ''
If it is asking for Authentication, please double-check the following:
Your SMTP settings
The email that you're trying to send mails from belongs to the verified domain. e.g. if you have verified example.com but you try sending emails from something#gmail.com, it is going to ask for gmail auth credentials.

Django sending Email confusion

I've used one application with sending email to the user for notification. but in that application setting.py file contains some confusing terms like
in
setting file
EMAIL_USE_TLS = True
I'm not sure what this is and also
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'rquest186#gmail.com'
what is the variety in this two
and if host is declared here then
mail.py
def send_mail(title,message,reciver):
try:
mailS = 'smtp.gmail.com'
mailP = 587
mailUsr = "idefusiontest2015#gmail.com"
mailPass = "********"
# Create a text/plain message
msg = MIMEMultipart('alternative')
msg['Subject'] = title
msg['From'] = mailUsr
msg['To'] = reciver
html="<html><head></head><body><p>"+message.replace("\n","<br>")+"</p></body></html>"
part2 = MIMEText(html, 'html')
msg.attach(part2)
# Send the message via our own SMTP server, but don't include the
s = smtplib.SMTP(mailS,mailP)
s.ehlo()
s.starttls()
s.ehlo()
s.login(mailUsr,mailPass)
s.sendmail(mailUsr, [reciver], msg.as_string())
s.quit()
except Exception as e:
print(e)
in this
mailUsr = "idefusiontest2015#gmail.com" ???? what's this for ?
I'm new to this. and it's confusing for me.
thanks in adv.
You need to provide a gmail account to send mail from:
mailUsr = "idefusiontest2015#gmail.com"
mailPass = "IDEF2017"
MailUsr is the emailid and MailPass is passowrd of that account.
It is like for sending mail you are logging to gmail account using these emailid and password and then sending the mail.
So if you want to send then you need to use your emailid and password in place of that.
settings.py
You need to have these settings.
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = 'username'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST is the smtp service you are using. In my case it is sendgrid in your case gmail.
EMAIL_HOST_USER is the username from that smtp service in your case your gmailid and EMAIL_HOST_PASSWORD password for that account.
I think it should be clear to you by now.
The the values from settings.py file will be automatically used while sending mail when if you are using django mail sending package like EmailMessage() for SendMail link
the second one that you are using is native python package . on that you have to explicitly provide the username and password and other configurations
sorry about the language .. :)

Categories