alternatives to gmail usage for django password reset - django

settings.py
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp.gmail.com"
EMAIL_PORT = "587"
EMAIL_USE_TLS = True
EMAIL_HOST_USER = "myemail"
EMAIL_HOST_PASSWORD = "mypassword"
i am trying to implement django password reset, but i need to create app password in gmail which requires two-step verification which is not allowed by google in my country Nigeria
what alternative do i have so i can implement django password reset?

SendGrid (Docs to setup for Django, I have used this one)
MailGun
You can get plenty more by searching around yourself.
Django also has libraries that will do the work for you, some examples are,
django-anymail
django-mailer
django-templated-email

Related

How to send with Sendgrid a reset password email from a Django app deployed in Heroku?

I have been struggling for a while in trying to correctly setup the settings.py to send an email for password reset.This is my current configuration:
SENDGRID_API_KEY = os.environ["SENDGRID_API_KEY"]
SENDGRID_PASSWORD= os.environ["SENDGRID_PASSWORD"]
SENDGRID_USERNAME= os.environ["SENDGRID_USERNAME"]
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = os.environ['SENDGRID_USERNAME']
#EMAIL_HOST_USER = 'apikey'
EMAIL_HOST_PASSWORD = os.environ["SENDGRID_PASSWORD"]
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = os.environ["DEFAULT_FROM_EMAIL"]
#SENDGRID_SANDBOX_MODE_IN_DEBUG = False
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
I have come across the following posts that are related to my problem but none of them have worked:
Sending SMTP email with Django and Sendgrid on Heroku
No module named 'sendgrid_backend' in django
Send email with Sendgrid in Django
Setting up email with Sendgrid in Heroku for a Django App
Heroku, Django, and Sendgrid - emails not sending?
When I used the EMAIL_BACKEND = "sendgrid_backend.SendgridBackend"(after I installed the django-sendgrid-v5 library) I didn't receive any error but I didn't receive any email :'( and in the previous cases I encountered the following error SMTPServerDisconnected at /password-reset/ and Connection unexpectedly closed. Any help, suggestion, comment, crazy idea is really appreciated because I have spent several hours in this problem that will be a milestone in my project.
Thank you everyone :)
I had a similar issue deploying a Django app on Google Cloud App Engine. The following configuration (in settings.py) worked for me:
SENDGRID_API_KEY = os.getenv('SENDGRID_API_KEY')
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = 'apikey' # Exactly that.
EMAIL_HOST_PASSWORD = SENDGRID_API_KEY
EMAIL_PORT = 587 # 25 or 587 (for unencrypted/TLS connections).
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = os.getenv('DEFAULT_FROM_EMAIL')
For SENDGRID_API_KEY, use the API key created in the 'Email API/Integration Guide' section. In your case, choose the SMTP Relay option.
For DEFAULT_FROM_EMAIL, use the verified single sender email. You can find it in 'Settings/Sender Authentication'. This is what you type in "from email address" when you create a Sender. More details here.
I don't recommend Robert D's answer because by using ALLOWED_HOSTS = ['*'] you will be prone to HTTP Host header attacks. From the documentation:
"A value of '*' will match anything; in this case you are responsible to provide your own validation of the Host header (perhaps in a middleware; if so this middleware must be listed first in MIDDLEWARE)."
More details here.
I sympathise, having also spent too long on this. But just fixed it today, with as little as the following added into settings.py (and everything else 'out of the box' from Django re password reset).
ALLOWED_HOSTS = ['*']
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 send report mail like Google

I have a web using Django framework run in localhost, I want web send email automatically to a email address, but I have a trouble in config EMAIL_HOST, EMAIL_HOST_USER, EMAIL_HOST_PASSWORD and EMAIL_PORT in settings.py
this is settings.py I configured:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False
EMAIL_HOST = 'localhost'
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_PORT = 25
How can I fix to send email?
Your project runs on localhost but your mailserver runs on google
try this
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = EMAIL_HOST_USER
EMAIL_HOST_PASSWORD = EMAIL_HOST_PASSWORD
You will need to set up Gmail, say with an application password.
See the google guide here and for app passwords here
If you connect using SSL or TLS, you can send mail to anyone with
smtp.gmail.com.
Note: Before you start the configuration, we recommend you set up App
passwords for the the desired account. Learn more at Sign in using App
Passwords and Manage a user's security settings.
Connect to smtp.gmail.com on port 465, if you’re using SSL. (Connect
on port 587 if you’re using TLS.) Sign in with a Google username and
password for authentication to connect with SSL or TLS. Ensure that
the username you use has cleared the CAPTCHA word verification test
that appears when you first sign in.
But if you are using gmail then you should look into the gmail api because then you can deal with inbound mails and you can use labels etc to manage the mails, it works well eventually once you get your head around oAuth etc. I know you didn't ask about that, but I personally find it useful.

SMTPSenderRefused at /users/password-reset/ (530, b'5.5.1 Authentication Required. Learn more at\n5.5.1 https://support.google.com/ma

I am getting this error while sending mail using django.
/usr/lib/python3.6/smtplib.py in sendmail, line 867
/usr/lib/python3.6/smtplib.py in sendmail
raise SMTPSenderRefused(code, resp, from_addr)
tried mailjet also same issues
If your are using Google SMTP make sure you have the following settings set in your settings.py file:
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'user emailid'
EMAIL_HOST_PASSWORD = 'password'
Also make sure you are logged in with gmail with the provided email id and password in your machine.
Also you need to enable access for less secure apps in your Google account. Here is the link to help you change your Google Account configuration settings link
If you saved your email/password in environ variable for the first time. Please close your terminal and open it again, I hope this will solve your problem. I have run into the same problem and solved issues just like this.
You need to create app password via your google account.
You can't use your email address to send mail.
Go to this link: https://myaccount.google.com/security
For me the error was caused by:
EMAIL_HOST_USER = os.getenv('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = os.getenv('EMAIL_HOST_PASSWORD')
as the env variables where not correctly imported.
Also remember to enable access for less secure apps in your Google account.
Your users must be active and have valid e-mail.
Go here https://myaccount.google.com/security, press on app password and gererate 16-symbolic password and put it to settings.
And use it in settings.py:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'put here your email-address with 16-symbolic password'
EMAIL_HOST_PASSWORD = 'put here your 16-symbols symbolic'

Need clarification in Django mail sending scenario

I build a mail sending function in django.I did it by referring django Doc .
In doc to specify a email backend,need to add this line in settings.py
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
settings.py for email
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'anjunair#gmail.com'
EMAIL_HOST_PASSWORD = '*********'
DEFAULT_FROM_EMAIL = 'quartentine#name.com'
Mail is sending to the email if the EMAIL_BACKEND removed from settings.Need some clarification about this.
Thanks
The docs don't tell you to do that. That console email backend is specifically to NOT use SMTP - it outputs directly to the console.
Remove it, and keep it that way if you want to send via smtp (gmail).

How can I send e-mail from django using the google smtp server?

I'm looking at https://docs.djangoproject.com/en/dev/topics/email/
My question is, is there way I can use smtp.google.com without authentication or without having to put my auth information into settings.py or as a parameter in the django.core.mail.send_mail function?
At this point I'm looking for best practices for using smtp.google.com on django, I understand there are better solutions such as http://sendgrid.com/
You cannot use smpt.gmail.com without providing your auth_information i.e your gmail password.
However you can put your auth information in a local_settings.py and do not add this local_settings in version control so no one except you would see this file. Include this local_settings in your settings.py.
settings.py
...
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
...
...
from local_settings import *
local_settings.py
EMAIL_HOST_USER = 'user#gmail.com'
EMAIL_HOST_PASSWORD = 'yourpassword'
try including this in settings.py:
# Email configuration.
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'user#domain.com'
EMAIL_HOST_PASSWORD = 'yourpassword'
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'user#domain.com'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
If you have a web domain provider (like namecheap, godady, etc) you can associate you domain (mycompany.com) with Gmail. For that feature ask help in your domain provider or look info in Internet:
http://www.namecheap.com/support/knowledgebase/article.aspx/1244/78/
http://help.squarespace.com/customer/portal/articles/581494-how-do-i-set-up-google-apps-for-my-domain-
Hope it helps,
cheers.