I have the following set up below:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL__USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = None #'user#gmail.com'
EMAIL_HOST_PASSWORD = None #'password'
DEFAULT_FROM_EMAIL = 'user#gmail.com'
SERVER_EMAIL = 'user#gmail.com'
EMAIL_PORT = 587
in settings.py. However, when I call password_reset, which handles sending an email in Django, SMTP AUTH extension not supported by server. is thrown. Is there an additional step to the password_reset() method? I'm simply passing this to my free smtp.gmail.com server through my Gmail account.
You have a double underscore in the EMAIL_USE_TLS setting.
Additional steps to set up Gmail SMTP:
-Make sure to enable IMAP under Gmail -> Cog icon -> Settings -> Forward and POP/IMAP
-Make sure to let less-secure apps access the account (at your own risk)
Related
I have these settings
EMAIL_HOST = 'smtpout.secureserver.net'
EMAIL_HOST_USER = 'username#domain.com'
EMAIL_HOST_PASSWORD = 'password'
DEFAULT_FROM_EMAIL = 'username#domain.com'
SERVER_EMAIL = 'username#domain.com'
EMAIL_PORT = 465
EMAIL_USE_TLS = True
SMTP_SSL = True
Speaking to Godaddy I have found out these are the ports and settings
smtpout.secureserver.net
ssl
465
587
TLS ON
3535
TLS ON
25
TLS ON
80
TLS ON
or
TLS OFF
I have tried all the combinations. If I set TLS to True I am getting
STARTTLS extension not supported by the server.
If I set to 465 I am getting
If I set other combinations like
EMAIL_HOST = 'smtpout.secureserver.net'
EMAIL_HOST_USER = 'username#domain.com'
EMAIL_HOST_PASSWORD = 'password'
DEFAULT_FROM_EMAIL = 'username#domain.com'
SERVER_EMAIL = 'username#domain.com'
EMAIL_PORT = 25
EMAIL_USE_TLS = False
For verification, I used Google Mail settings to test if the email sending via python works, and it is working.
Now I want to switch to GoDaddy and I know for the email we use TLS to log in even for POP3 download and it is working, so I am not sure why python / Django option is not working. Can you please help?
I have called Godaddy, they cannot help because it is a software issue - all their settings and ports are working, so I have no one to ask.
This worked for me with my GoDaddy email. Since GoDaddy sets up your email in Office365, you can use smtp.office365.com.
settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.office365.com'
EMAIL_HOST_USER = 'myemail#GoDaddyDomain.com'
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
EMAIL_HOST_PASSWORD = 'myPassword'
EMAIL_PORT = 587
EMAIL_USE_SSL = False
EMAIL_USE_TLS = True
method in views.py that handles sending email. The email variable is from a user form.
from django.conf import settings
from django.core.mail import EmailMessage
def send_email(subject, body, email):
try:
email_msg = EmailMessage(subject, body, settings.EMAIL_HOST_USER, [settings.EMAIL_HOST_USER], reply_to=[email])
email_msg.send()
return "Message sent :)"
except:
return "Message failed, try again later :("
I found this code worked for me.. Hope this will be useful to somebody.I was using SMTP godaddy webmail..you can put this code into your django setting file.
Since you cannot set Both SSL and TSL together... if you do so you get the error
something as, At one time either SSL or TSL can be true....
setting.py
# Emailing details
EMAIL_HOST = 'md-97.webhostbox.net'
EMAIL_HOST_USER = 'mailer#yourdomain'
EMAIL_HOST_PASSWORD = 'your login password'
EMAIL_PORT = 465
EMAIL_USE_SSL = True
I managed to decide to access the site
https://sso.secureserver.net/?app=emailsetup&realm=pass&
It seems that when accessing, you can enable email for external use.
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtpout.secureserver.net'
EMAIL_HOST_USER='aXXXX#xxxx'
EMAIL_HOST_PASSWORD='AsgGSDAGSasdsagas'
DEFAULT_FROM_EMAIL='aXXXX#xxxx'
EMAIL_PORT=465
EMAIL_USE_SSL=True
EMAIL_USE_TLS=False
It worked for me
It's been a while but, maybe the answer can help somebody else. I just talked to GoDaddy about the issue and the needed configration they told me was like,
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtpout.secureserver.net'
EMAIL_HOST_USER = env('EMAIL_HOST_USER')
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
SERVER_EMAIL = EMAIL_HOST_USER
EMAIL_HOST_PASSWORD = env('EMAIL_HOST_PASSWORD')
EMAIL_PORT = 80
EMAIL_USE_SSL = False
EMAIL_USE_TLS = True
these are the django config settings but, I'm sure that it can be copied to other platforms.
Also, the email dns configration they provided was,
use 'smtpout.asia.secureserver.net' as EMAIL_HOST in Django settings.py. you can refer to the GoDaddy email help page link.
https://in.godaddy.com/help/mail-server-addresses-and-ports-for-business-email-24071
In my case, this way work for me:
#settings.py
EMAIL_BACKEND='django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST='smtpout.secureserver.net'
EMAIL_PORT=465
EMAIL_USE_SSL=True
EMAIL_USE_TLS=False
EMAIL_HOST_USER='your#domain'
EMAIL_HOST_PASSWORD='yourpass'
ADMIN_EMAIL='your#domain'
I am trying to send emails from my django app using the the gmail smtp servers. The emails are being sent when I run the application on my local server. But I'm getting an SMTP Authentication Error while using it on heroku.
Traceback - link
settings.py -
# Email configuration.
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '***************#gmail.com'
EMAIL_HOST_PASSWORD = '************'
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = '******************#gmail.com'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
And I have rechecked the account password, also I have enabled the access of less secure apps from my google account. But still I am getting this error.
Disabling CAPTCHA for clients
If you are not using 2-factor authentication and you have verified the credentials in your Python source are correct, follow these steps:
Login to gmail in your browser
Navigate to the DisplayUnclockCaptcha page.
Click the continue button, and you will see the message
Account access enabled Please try signing in to your Google account again from your new device or application.
Run your Python script - your login attempt should be successful.
Try using sendgrid, because gmail smtp has some problem. I too was unable to do using gmail smtp. But it worked perfectly using sendgrid. And this is also free for basic use.
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = 'username'
EMAIL_HOST_PASSWORD = 'userpassword'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'asdf#example.com'
Change from mail(#gmail.com) domain to your company domain .then it will work. we can't use from mail domain #gmail.com, DEFAULT_FROM_EMAIL = '******************#yourcompanydomain.com'
I registered a domain and a private email using namecheap.com. I am trying to send an email from this private email. However, I get the error in the title.
In my settings.py, I have these settings:
EMAIL_HOST = 'mail.privateemail.com'
EMAIL_HOST_USER = 'contact#mysite.com'
EMAIL_HOST_PASSWORD = 'my password'
EMAIL_PORT = 587
EMAIL_USE_TLS = False
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
And I am trying to send my mail through a view:
send_mail(
'Subject here',
'Here is the message.',
'contact#mysite.com',
['myname#gmail.com'],
fail_silently=False,
)
I get this error :
SMTP AUTH extension not supported by server.
This is happening because you have conflicting settings:
EMAIL_PORT = 587 # Port 587 is reserved for TLS
EMAIL_USE_TLS = False # But you have disabled TLS
You either need to set EMAIL_USE_TLS to True or use the default port for unencrypted connections (25).
I was searching answer for this since 4 hours. I still dont know why this configuration works for me, but yes, IT WORKS for me.
I simply removed,
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
from my settings.py, and add below configuration in settings.py
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'username#domain.com'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
Remove the following config since "SMTP AUTH extension not supported by" your EMAIL_HOST:
EMAIL_HOST_PASSWORD = 'my password'
EMAIL_PORT = 587
I was using a server that is not Gmail by default and turns out to be a port issue, I found that I was using the wrong port, I changed it to 465 for SMTP with TLS, Thanks to this link..
So here are the settings I used:
EMAIL_PORT = 465
EMAIL_USE_TLS = True
I use Sentry to log exceptions for my project and all is OK.
But I don't know how to make Sentry auto-send notifications to my email (example as gmail,v.v) when there is an exception.
Help me.
# This is config setting:
# For more information check Django's documentation:
# https://docs.djangoproject.com/en/1.3/topics/email/?from=olddocs#e-mail-backends
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'localhost'
EMAIL_HOST_PASSWORD = ''
EMAIL_HOST_USER = ''
EMAIL_PORT = 25
EMAIL_USE_TLS = False
# The email address to send on behalf of
SERVER_EMAIL = 'my_mail#gmail.com'
Check your sentry settings
Go to http:///account/settings/notifications/
P.S. Django usually email to addresses in "ADMIN" setting
In my settings.py, I have the following:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# Host for sending e-mail.
EMAIL_HOST = 'localhost'
# Port for sending e-mail.
EMAIL_PORT = 1025
# Optional SMTP authentication information for EMAIL_HOST.
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_USE_TLS = False
My email code:
from django.core.mail import EmailMessage
email = EmailMessage('Hello', 'World', to=['user#gmail.com'])
email.send()
Of course, if I setup a debugging server via python -m smtpd -n -c DebuggingServer localhost:1025, I can see the email in my terminal.
However, how do I actually send the email not to the debugging server but to user#gmail.com?
After reading your answers, let me get something straight:
Can't you use localhost(simple ubuntu pc) to send e-mails?
I thought in django 1.3 send_mail() is somewhat deprecated and EmailMessage.send() is used instead?
I use Gmail as my SMTP server for Django. Much easier than dealing with postfix or whatever other server. I'm not in the business of managing email servers.
In settings.py:
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'me#gmail.com'
EMAIL_HOST_PASSWORD = 'password'
NOTE: In 2016 Gmail is not allowing this anymore by default. You can either use an external service like Sendgrid, or you can follow this tutorial from Google to reduce security but allow this option: https://support.google.com/accounts/answer/6010255
Send the email to a real SMTP server. If you don't want to set up your own then you can find companies that will run one for you, such as Google themselves.
Create a project: django-admin.py startproject gmail
Edit settings.py with code below:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'youremail#gmail.com'
EMAIL_HOST_PASSWORD = 'email_password'
EMAIL_PORT = 587
Run interactive mode: python manage.py shell
Import the EmailMessage module:
from django.core.mail import EmailMessage
Send the email:
email = EmailMessage('Subject', 'Body', to=['your#email.com'])
email.send()
For more informations, check send_mail and EmailMessage features in documents.
UPDATE for Gmail
Also if you have problems sending email via gmail remember to check this guides from google.
In your Google account settings, go to Security > Account permissions > Access for less secure apps and enable this option.
Also create an App specific password for your gmail after you've turned on 2-step-verification for it.
Then you should use app specific password in settings. So change the following line:
EMAIL_HOST_PASSWORD = 'your_email_app_specific_password'
Also if you're interested to send HTML email, check this out.
My site is hosted on Godaddy and I have a private email registered on the same.
These are the settings which worked for me:
In settings.py:
EMAIL_HOST = 'mail.domain.com'
EMAIL_HOST_USER = 'abc#domain.com'
EMAIL_HOST_PASSWORD = 'abcdef'
DEFAULT_FROM_EMAIL = 'abc#domain.com'
SERVER_EMAIL = 'abc#domain.com'
EMAIL_PORT = 25
EMAIL_USE_TLS = False
In shell:
from django.core.mail import EmailMessage
email = EmailMessage('Subject', 'Body', to=['def#domain.com'])
email.send()
Then I got "1" as the O/P i.e. Success. And I received the mail too. :)
What is the meaning of domain.com?
For Django version 1.7, if above solutions dont work then try the following
in settings.py add
#For email
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'sender#gmail.com'
#Must generate specific password for your app in [gmail settings][1]
EMAIL_HOST_PASSWORD = 'app_specific_password'
EMAIL_PORT = 587
#This did the trick
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
The last line did the trick for django 1.7
You need to use smtp as backend in settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
If you use backend as console, you will receive output in console
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
And also below settings in addition
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'urusername#gmail.com'
EMAIL_HOST_PASSWORD = 'password'
If you are using gmail for this, setup 2-step verification and Application specific password and copy and paste that password in above EMAIL_HOST_PASSWORD value.
I found using SendGrid to be the easiest way to set up sending email with Django. Here's how it works:
Create a SendGrid account (and verify your email)
Add the following to your settings.py:
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = '<your sendgrid username>'
EMAIL_HOST_PASSWORD = '<your sendgrid password>'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
And you're all set!
To send email:
from django.core.mail import send_mail
send_mail('<Your subject>', '<Your message>', 'from#example.com', ['to#example.com'])
If you want Django to email you whenever there's a 500 internal server error, add the following to your settings.py:
DEFAULT_FROM_EMAIL = 'your.email#example.com'
ADMINS = [('<Your name>', 'your.email#example.com')]
Sending email with SendGrid is free up to 12k emails per month.
I had actually done this from Django a while back. Open up a legitimate GMail account & enter the credentials here. Here's my code -
from email import Encoders
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
def sendmail(to, subject, text, attach=[], mtype='html'):
ok = True
gmail_user = settings.EMAIL_HOST_USER
gmail_pwd = settings.EMAIL_HOST_PASSWORD
msg = MIMEMultipart('alternative')
msg['From'] = gmail_user
msg['To'] = to
msg['Cc'] = 'you#gmail.com'
msg['Subject'] = subject
msg.attach(MIMEText(text, mtype))
for a in attach:
part = MIMEBase('application', 'octet-stream')
part.set_payload(open(attach, 'rb').read())
Encoders.encode_base64(part)
part.add_header('Content-Disposition','attachment; filename="%s"' % os.path.basename(a))
msg.attach(part)
try:
mailServer = smtplib.SMTP("smtp.gmail.com", 687)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(gmail_user, gmail_pwd)
mailServer.sendmail(gmail_user, [to,msg['Cc']], msg.as_string())
mailServer.close()
except:
ok = False
return ok
You could use "Test Mail Server Tool" to test email sending on your machine or localhost. Google and Download "Test Mail Server Tool" and set it up.
Then in your settings.py:
EMAIL_BACKEND= 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'localhost'
EMAIL_PORT = 25
From shell:
from django.core.mail import send_mail
send_mail('subject','message','sender email',['receipient email'], fail_silently=False)
Late, but:
In addition to the DEFAULT_FROM_EMAIL fix others have mentioned, and allowing less-secure apps to access the account, I had to navigate to https://accounts.google.com/DisplayUnlockCaptcha while signed in as the account in question to get Django to finally authenticate.
I went to that URL through a SSH tunnel to the web server to make sure the IP address was the same; I'm not totally sure if that's necessary but it can't hurt. You can do that like so: ssh -D 8080 -fN <username>#<host>, then set your web browser to use localhost:8080 as a SOCKS proxy.
For SendGrid - Django Specifically:
SendGrid Django Docs here
Set these variables in
settings.py
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = 'sendgrid_username'
EMAIL_HOST_PASSWORD = 'sendgrid_password'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
in views.py
from django.core.mail import send_mail
send_mail('Subject here', 'Here is the message.', 'from#example.com', ['to#example.com'], fail_silently=False)
below formate worked for me
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True EMAIL_HOST = 'mail.xxxxxxx.xxx'
EMAIL_PORT = 465
EMAIL_HOST_USER = 'support#xxxxx.xxx'
EMAIL_HOST_PASSWORD = 'xxxxxxx'
In settings.py configure the email as following
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'user#gmail.com'
EMAIL_HOST_PASSWORD = 'password'
In most of the cases Gmail settings is missed out. Make sure that the less secure app access is turned on. You can also check the procedure here
Then send email within views
from django.core.mail import send_mail
def send(request):
send_mail(
‘Email Subject here’,
‘Email content’,
settings.EMAIL_HOST_USER,
[‘emailto#gmail.com’],
fail_silently=False)