Django registration SMTPServerDisconnected error - django

I use django-registration for my project to manage user registration, login, etc. But When I sign up for an account I came across this problem:
SMTPServerDisconnected
For the record, I did configure email related settings in my settings.py:
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 465
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'myemail#gmail.com'
EMAIL_HOST_PASSWORD = 'mypassword'
Also I have all the templates needed and accessible. So this problem doesn't have anything to do with that.
More Error description:
After I click on the send activation email, it takes a long time before it finally give that error.
Here is the traceback (not complete):
SMTPServerDisconnected at /accounts/register/
Connection unexpectedly closed
last trace back:
/usr/lib/python2.7/smtplib.py in getreply
line = self.file.readline()
except socket.error as e:
self.close()
raise SMTPServerDisconnected("Connection unexpectedly closed: "
+ str(e))
if line == '':
self.close()
raise SMTPServerDisconnected("Connection unexpectedly closed")
...
if self.debuglevel > 0:
print>>stderr, 'reply:', repr(line)
resp.append(line[4:].strip())
code = line[:3]
# Check that the error code is syntactically correct.
# Don't attempt to read a continuation line if it is broken.
Thanks for any suggestion.

I think at least one setting is incorrect. Port 587 is required for TLS [1]
EMAIL_PORT = 587
[1] http://support.google.com/mail/bin/answer.py?hl=en&answer=13287

Finally I figured this out. I post my solution here in case someone else get stuck here. The problem is the Gmail port. Use 587 and it worked.
I saw it here: https://code.djangoproject.com/ticket/9575
I wonder why some people can use 465 and some can't. It cost me a few hours to find out. Hope your guys won't!
EDIT: See here for more dicussion about use of port.
To use port 465, you need to call smtplib.SMTP_SSL(). Currently, it looks like Django only uses smtplib.SMTP().
Seems 587 is the right choice.

Meanwhile, you might want to check https://github.com/bancek/django-smtp-ssl

Django Gmail Confi # settings.py
EMAIL_BACKEND ='django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_SSL = True # use port 465
EMAIL_USE_TLS = False # use port 587
EMAIL_PORT = 465 # OR 587
EMAIL_HOST_USER = os.environ.get('USER_EMAIL')
EMAIL_HOST_PASSWORD =os.environ.get('USER_EMAIL_PASS')
helper.py (function)
from django.core.mail import send_mail
def send(sub=None,message=None,recipient=[]):
# def send_mail(
# subject,
# message,
# from_email,
# recipient_list,
# fail_silently=False,
# auth_user=None,
# auth_password=None,
# connection=None,
# html_message=None):
send_mail(subject='contact mail'
,message='Test Mail'
,from_email=EMAIL_HOST_USER
,recipient_list=['mail_list']
,fail_silently=False)
return True

If you are not having any luck with the above answers, you may want to check to see if you have set your DEFAULT_FROM_EMAIL in the settings.py
# project/settings.py
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 465
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'myemail#gmail.com'
EMAIL_HOST_PASSWORD = 'mypassword'
DEFAULT_FROM_EMAIL = 'myemail#gmail.com'

Related

Unable to get send_mail to send an email message Django

I posted a question earlier where I asked how to get my email to send and was told that it's the provider, so I tried 3 providers and the send_mail and/or EmailMessage function doesn't work with any of them.
So, I strongly think it's something related to my set-up. I get a message in the send_email folder, but no email ever sends and no error is logged.
Here is my settings.py file:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'myemails#gmail.com'
EMAIL_HOST_PASSWORD = 'pass'
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
SERVER_EMAIL = 'myemail#gmail.com'
Might someone else have an idea?

Django sendmail SMTPDataError

I am getting the below error while trying to use Django sendmail using Outlook SMTP
SMTPDataError at /distribute/
(554, '5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied;
Failed to process message due to a permanent exception with message
Cannot submit message. 16.55847:0C0F0000,
17.43559:0000000094000000000000000000000000000000, 20.52176:140F0E852800101064010000, 20.50032:140F0E858817101069010000, 0.35180:0A00E781, 255.23226:6E010000, 255.27962:0A000000, 255.27962:0E000000, 255.31418:0A000000, 16.55847:86000000, 17.43559:0000000068010000000000000000000000000000, 20.52176:140F0E85280010100A00F736, 20.50032:140F0E85881710100A00F836, 0.35180:8C010000, 255.23226:40000730, 255.27962:0A000000, 255.27962:32000000, 255.17082:DC040000, 0.27745:0A001780, 4.21921:DC040000, 255.27962:FA000000, 255.1494:A4010000, 0.37692:05000780, 0.37948:00000000, 5.33852:00000000534D545000000780, 4.56248:DC040000, 7.40748:010000000000010B05000780, 7.57132:000000000000000005000780, 1.63016:32000000, 4.39640:DC040000, 8.45434:824D851FB0676A47B811311E3F17990F00000000, 5.10786:0000000031352E32302E313239342E3032343A5455345052383430314D42303436323A34333038323065332D393530612D346435362D383863332D3037363837616130336664330005000780,
255.1750:0A008984, 255.31418:41010000, 0.22753:0A001986, 255.21817:DC040000, 4.60547:DC040000, 0.21966:4B010000, 4.30158:DC040000 [Hostname=TU4PR8401MB0462.NAMPRD84.PROD.OUTLOOK.COM]')
My settings are as below:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp-mail.outlook.com'
EMAIL_HOST_USER = '********'
EMAIL_HOST_PASSWORD = '********'
EMAIL_PORT = 587
Please help
I had an error similar to yours, and I resolved it as follows, two points that I think you have to pay attention to are:
EMAIL_HOST normally email hosts have this format ** smtp.nameserver.com **, example:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.outlook.com'
EMAIL_HOST_USER = '********'
EMAIL_HOST_PASSWORD = '********'
EMAIL_PORT = 587
When sending the email, the send_mail method has to send the email from an address in your domain, example:
from django.core.mail import send_mail
send_mail(
'Subject here',
'Here is the message.',
'from#outlook.com', # pay attention here I had a problem because of that
['to#example.com'],
fail_silently=False,
)

Email send in django

I am trying to send the email from django web app. I used following
from django.core.mail import send_mail
send_mail('test email', 'hello world', 'your#email.com', ['aman.kumar#thoughts2binary.com'])
my setting is
DEFAULT_FROM_EMAIL = 'support#indianangelnetwork.com'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'support#indianangelnetwork.com'
EMAIL_HOST_PASSWORD = 'XXXXXXXXXX'
i am always getiing the mail from "support#indianangelnetwork.com". Although i am passing the send_from value.
This might be because you did not specify the password for your#email.com.
As a result Django falls back to the default settings.
See documentaion

Django send_mail not working with gmail

I have been trying everything to get django to send a test email, with no success. My test email is being sent from a python anywhere dev site. Here is my views ajax:
def ajaxLearning(request):
if request.method == 'GET':
from django.core.mail import send_mail
send_mail('Put your Email subject here', 'Put your Email message here.',
'myspamgoes#gmail.com', ['someemail#yahoo.com'],
fail_silently=False)
return HttpResponse("end");
else:
pass
And here is my settings.py:
DEFAULT_FROM_EMAIL = 'myspamgoes#gmail.com'
SERVER_EMAIL = 'myspamgoes#gmail.com'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'myspamgoes#gmail.com'
EMAIL_HOST_PASSWORD = 'mypassword'
At this point I feel as if I am making some higher level mistake such as, using the wrong version of django, failing to install something crucial, or doing something wrong on the gmail side. For the password, which I changed earlier today, I am using the one that I would use to normally sign in to my account. Thank you for taking the time to read my question!
Change in settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST='smtp.gmail.com'
EMAIL_PORT=587
EMAIL_HOST_USER = 'myemailhere#gmail.com'
EMAIL_HOST_PASSWORD = '**********'
DEFAULT_FROM_EMAIL = 'myemailhere#gmail.com'
EMAIL_USE_TLS = True

Django send_mail not working - No email delivered

When the view that sends the email is used nothing happens, i then entered send_mail(...) into the python shell and it returned 1 but i didn't receive any emails.
This is my settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'senderaddress#gmail.com'
EMAIL_HOST_PASSWORD = 'Password1234!'
EMAIL_USE_TLS = True
This is the view:
def send_email(request):
send_mail('Request Callback', 'Here is the message.', 'senderaddress#gmail.com',
['recipientaddress#gmail.com'], fail_silently=False)
return HttpResponseRedirect('/')
Adjust your settings thus:
DEFAULT_FROM_EMAIL = 'workorbit#gmail.com'
SERVER_EMAIL = 'workorbit#gmail.com'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'workorbit#gmail.com'
EMAIL_HOST_PASSWORD = 'P#ssw0rd5'
Adjust your code:
from django.core.mail import EmailMessage
def send_email(request):
msg = EmailMessage('Request Callback',
'Here is the message.', to=['charl#byteorbit.com'])
msg.send()
return HttpResponseRedirect('/')
Google now provides a method to generate a password that you can use for applications that need to relay mail. its different from the password that you would use to login through webmail.
Sign in to Google and start using App Passwords. This allows you to use a 16 digit password to access google services including ability to send out email. Refer below
https://support.google.com/accounts/answer/185833?hl=en