This is my SMTP configuration for my web page.
#SMTP (Simple Mail Transfert Protocole) Configuration
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = '*****************'
EMAIL_HOST_PASSWORD = '*************'
I created a web page using python and Django where the user has to login before.
When the user has forgotten his password, he has the possibility to reset his password.
to reset his password, the user has to enter his email then the link will be sent to his email provided during his registration.
*but when the user enters his email then clicks on send, instead to send the link into his email account, the link is redirect/ sent, to the "EMAIL_HOST_USER".*
Problem/Error
How should I configure the SMTP (Simple Mail Transfert Protocole) so that the user receives the link of the password reset into his email account provided during his registration?
please help me.
Related
I'm currently building a contact form for my website in Django.
The only problem is that the email is not being sent when the form is submitted.
This is the code:
settings.py:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = "c******o#gmail.com"
EMAIL_HOST_PASSWORD = '****'
EMAIL_PORT = '587'
views.py:
sender_name = form.cleaned_data['nome_completo']
sender_email = form.cleaned_data['email']
message = "{0} has sent you a new message:\n\n{1}".format(sender_name, form.cleaned_data['messaggio'])
send_mail('New Enquiry', message, sender_email, ['c******o#gmail.com'])
My thought:
Since I'm in a virtualenv, when I submit the form, the terminal displays that it was successfully submitted, and gets me back the code right, maybe the email is not sent because of that, or maybe because I'm using a gmail account? Thanks!
Since you are using an SMTP server, why not use the following backend:
django.core.mail.backends.smtp.EmailBackend
Also, if you are using Gmail, make sure of the following:
Two-Factor authentication is enabled on account
You are using an app password.
You can find these on the security tab on your google account page:
https://myaccount.google.com/security
So the issue is with EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
This outputs emails to your console for debugging instead of actually sending emails. (See https://docs.djangoproject.com/en/3.1/topics/email/#console-backend)
Don't set EMAIL_BACKEND to anything for production as it defaults to django.core.mail.backends.smtp.EmailBackend. Then your EMAIL_HOST settings will take effect and the email should be sent out.
I am developing password reset part of the project. I am using django_rest_passwordreset to get the password reset. I am using mailjet smtp. I could not send the email to the user.
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'in-v3.mailjet.com'
# EMAIL_PORT = 465
EMAIL_PORT = 587
EMAIL_USE_TLS = True
# EMAIL_USE_SSL = True
EMAIL_HOST_USER = '5e4329460b3c88f1d24d19c3e7374548aa213da%asasd1asd'
EMAIL_HOST_PASSWORD = 'a6c5ab2515d6ae761253a396453530ba$42asasdasdaasdasd'
If I change the EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' to the EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' it is printing it to the console. I have no idea why it is not working.
the part of the code where I am trying to send an email.
#receiver(reset_password_token_created)
def password_reset_token_created(sender, instance, reset_password_token, *args, **kwargs):
# send an e-mail to the user
context = {
'current_user': reset_password_token.user,
'username': reset_password_token.user.firstname,
'email': reset_password_token.user.email,
'reset_password_url': "{}?token={}".format(reverse('password_reset:reset-password-request'), reset_password_token.key)
}
# just checking if it works
send_mail('Hello from something', 'hello there', 'abdukhashimov#yandex.ru',
[reset_password_token.user.email, ], fail_silently=False)
# render email text
email_html_message = render_to_string('user_reset_password.html', context)
email_plaintext_message = render_to_string(
'user_reset_password.txt', context)
msg = EmailMultiAlternatives(
# title:
"Password Reset for {title}".format(title="Some website title"),
# message:
email_plaintext_message,
# from:
"noreply#somehost.local",
# to:
[reset_password_token.user.email]
)
msg.attach_alternative(email_html_message, "text/html")
msg.send()
I came up with a different solution. I used the google smtp service. I have followed the steps from this kinsta.com - steps to setup up google smtp.
Step1: The very first thing you will need to do is ensure that you have 2-step verification enabled on your primary Gmail account. Important: If you don’t do this you will get an invalid password error further below when trying to authenticate your email address. So first go and enable 2-step verification.
Step2: Next, you will need to generate an App password. You then use the app password in place of your personal Gmail password further below. This is the only way this process will work.
Step3: Now back in Gmail, go to settings, and can click on “Accounts and Import.” Then click on “Add another email address you own.”. Basically to the gmail and sign in with your account and go to the settings.
Step4: Enter your additional business name and business email that is on the custom domain.
(Extra Info). I usually use yandex mail and added it then it generated the followings.
Step5: It will then send an email confirmation code to the email you just added. You will need to click the link in the email to confirm it or manually enter the code (this proves that you are in fact the owner of the additional email account). And that’s it!
From my experience, you might need to tweak some settings from google if it did not work for you. For example, I read from other source, you might need to allow less secure apps from google. I have not done it as I was using yandex mail, I guess.
In case if you are not sure what to put in settings.py
EMAIL_HOST = 'smtp.yandex.ru' # in my case
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'added account'
EMAIL_HOST_PASSWORD = 'your password'
Credits to kinsta.com
i previously i was using gmail smtp to send mail**(working fine)** but now i created new account in sendgrid and im using free plan in my django project this my complete setting about send grid
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = 'apikey' # this is exactly the value 'apikey'
EMAIL_HOST_PASSWORD = 'SG.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' # this is API key
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
is any other settings required?? i am testing email using rest auth lib http://127.0.0.1:8000/rest-auth/password/reset/
is show msg like success": "Password reset e-mail has been sent."
but recipient did not received any mails but in sendgrid dashboard it is showing 9 or 10 etc msg delivered
I'm working on a Django application.
I have set up all my required password reset views and corresponding pages.
In the final step I want to use Send Grid in my application to send the emails. I have the following setting s in my base.py file
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST_USER = 'codesniper99' # email id
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_PORT = 587
EMAIL_HOST_PASSWORD = '****' #password
EMAIL_USE_TLS = True
where **** is my password for the username codesniper99 on sendgrid.com
But when I use the password reset function I get locally generated email to my account. Like when i put email for reset as akhilvaid21#gmail.com
I get this:
when I push my code to my production server and not local host then it doesn't work and no email is sent. What am I doing wrong?
Also how do I change the name of webmaster#localhost???
Make sure you have set DEFAULT_FROM_EMAIL and SERVER_EMAIL in your settings.
Many email providers will only let you send email from verified email addresses. It looks as if Sendgrid might be blocking emails because Django is using the default webmaster#localhost for DEFAULT_FROM_EMAIL.
I was trying to send a verification email at my program, when I use gmail it works and send the verification email but now im trying to use my own mail server and it started to raise this error
SMTPAuthenticationError at /accounts/register/
(535, '5.7.8 Error: authentication failed:')
any idea why?
# EMAIL SETTINGS
EMAIL_HOST = "smtp.xxxx.xxx"
EMAIL_PORT = "25"
EMAIL_HOST_USER = "no-reply#xxxxx.net"
EMAIL_HOST_PASSWORD = "xxxxxxxxxxxxxxxxxx"
# Controls whether a secure connection is used.
EMAIL_USE_TLS = True
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
Verify the username and password are exactly the same,
Do not give full e-Mail id if in case your smtp accepts just the username without domain
e.g.
e-Mail id : username#abc.com
in settings file, just give username when your smtp accepts it.