Password Reset-Sending mail doesnt work - python

Setting.py-
EMAIL_BACKEND = "mailer.backend.DbBackend"
EMAIL_SUBJECT_PREFIX = "[.....]"
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_PASSWORD = 'tester##abcd'
EMAIL_HOST_USER = 'tester.abcd#gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'tester.abcd#gmail.com'
DEFAULT_ADMIN_EMAIL = 'tester.abcd#gmail.com'
TEMPORARY_CC_EMAIL = 'tester.abcd#gmail.com'
CONTACTUS_EMAIL = 'tester.abcd#gmail.com'
JOBAPPLY_EMAIL = 'tester.abcd#gmail.com'
urls.py:
urlpatterns = patterns('django.contrib.auth.views',
url(r'^password-reset/$', 'password_reset', {
'template_name': 'profiles/password_reset_form.html',
'password_reset_form': PassResetForm
}, name='password-reset'),
url(r'^password-reset-process/$', 'password_reset_done', {
'template_name': 'profiles/password_reset_done.html',
}, name='password-reset-done'),
url(r'^password-reset-confirm/(?P<uidb36>[0-9a-zA-Z]{1,13})-(?P<token>.+)/$',
'password_reset_confirm',
{'template_name': 'profiles/password_reset_confirm.html',},
name='password-reset-confirm'),
url(r'^password-reset-complete', 'password_reset_complete', {
'template_name': 'profiles/password_reset_complete.html',
}, name='password-reset-complete'),
This is my code wheni enter my mail and click submit it correctly redirects to the next page but mail is not send,is there anything pblm with this code

You should start by testing if the problem comes from your code or the email backend.
Here is how to setup the Django console email backend:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
This should output emails in the console when you are running the server on your local dev machine python manage.py runserver.
If the emails are printed correctly into the console, then there is something wrong with your configuration either here:
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_PASSWORD = 'tester##abcd'
EMAIL_HOST_USER = 'tester.abcd#gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
or here:
EMAIL_BACKEND = "mailer.backend.DbBackend"

Related

Cpanel Email not authenticated

I am using cpanel email on gmail. But when sending mails through Django EmailAlternatives, the mail being sent is reported as dangerous. How do I make it safe, or if I am using PORT 465 and HOST as smtp.gmail.com, it is not working. Below given are my EMAIL Details.
WSGI_APPLICATION = 'backend.wsgi.application'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'mail.my_dot_in_domain'
EMAIL_HOST_USER = 'my_email'
EMAIL_HOST_PASSWORD = 'my_password'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
Screenshot to explain what mail says and all the details

Sending emails with EmailMessage does not work when I deploy my application

I am developing an application with django. When I send emails locally with EmailMessage it works, but after deployment on heroku it doesn't work anymore. Here is the code in views.py
from django.template.loader import render_to_string
message = render_to_string("elec_meter/activate_email.html",
{
"user": user, "domaine": request.META['HTTP_HOST'],
"uid": urlsafe_base64_encode(force_bytes(user.id)),
"token": default_token_generator.make_token(user),
"password": password,"matricule": agent.matricule
}
)
email_to_send = EmailMessage("Activation du compte", message, to=[email])
email_to_send.send()
in 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 = "my_email"
EMAIL_HOST_PASSWORD = "password"
EMAIL_USE_SSL = False
I need help please

SMTPSenderRefused at /accounts/signup/

I tried to configure sending email on registration using gmail server and i get these error:
(530, b'5.7.0 Authentication Required. Learn more at\n5.7.0 https://support.google.com/mail/?p=WantAuthError u2sm3847520edr.70 - gsmtp', 'webmaster#localhost').
These are my configurations in settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 465
EMAIL_USE_SSL = True
EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD')
I don't think you configured the environment variables.
$ export EMAIL_HOST_USER ="yournotsosecretemail"
$ export EMAIL_HOST_PASSWORD ="yourverysecretpassword"
$ python manage.py runserver
I guess that there are other ways to store environment variables, this is just one way. If you want some debugging help, add some print statements after the configuration.
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 465
EMAIL_USE_SSL = True
EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD')
print('Email:', EMAIL_HOST_USER)
print('Password:, 'EMAIL_HOST_PASSWORD)

django allauth isn't sending verification email after signup

I'm using django allauth for my user accounts. When I create an account, it successfully tells me it will send an email to the address for verification. However I don't receive this email.
This is my settings.py:
EMAIL_CONFIRMATION_SIGNUP = True
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
LOGIN_REDIRECT_URL = '/'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'my#gmail.com'
EMAIL_HOST_PASSWORD = 'password'
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

Setting up Email Backends with Django 1.6

I currently am using django-password-reset to assist users when they forget a password. Everything worked just fine while in development but now I am having issues setting up the email backend on my production server.
When a user enters their username or email into the password reset form and push the 'Recover Password' button that would normally trigger the password-reset email, the page starts to load infinitely. I am attempting to use a gmail account as my smtp server. I am assuming that there is some sort of issue with my settings.py file.
settings.py:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 465
EMAIL_HOST_USER = 'example#gmail.com'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'example#gmail.com'
If you have any idea what is wrong with my configuration or any other ways to set up my email backend advice would be greatly appreciated! Thanks
This works locally at least.
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'something#gmail.com'
EMAIL_HOST_PASSWORD = 'something'
EMAIL_USE_TLS = True

Categories