I'm trying to send emails with Amazon SES, but when I use default EMAIL_BACKEND raise error:
-- Config:
Error: raise SMTPServerDisconnected("Connection unexpectedly closed") smtplib.SMTPServerDisconnected: Connection unexpectedly closed If I use:
from https://github.com/bancek/django-smtp-ssl, works right. Code of this backend:
What the problem with default EMAIL_BACKEND? Why I can't use him? You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d71c947b-db14-4373-b412-41e5dc5a7cff%40googlegroups.com. For more options, visit https://groups.google.com/d/optout. |
On Tue, Mar 29, 2016 at 2:56 AM, Neto <[hidden email]> wrote: --
My config EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = "email-smtp.$zone.amazonaws.com" EMAIL_PORT = 587 EMAIL_HOST_USER = "$USER" EMAIL_HOST_PASSWORD = "$PASSWORD" EMAIL_USE_TLS = True Different port. I'm using python 3.4 | Raffaele Salmaso | https://salmaso.org | https://bitbucket.org/rsalmaso | https://github.com/rsalmaso You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABgH4JtaLbpDdFo7JzBA7R9BjEE6kU9nKRPT406N9SAttdC%2B9Q%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout. |
In reply to this post by Neto
On Mon, Mar 28, 2016 at 05:56:12PM -0700, Neto wrote:
> I'm trying to send emails with Amazon SES, but when I use default > EMAIL_BACKEND raise error: > > Config: > > EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' # this is > default > EMAIL_HOST = 'email-smtp...amazonaws.com' > EMAIL_PORT = 465 > EMAIL_HOST_USER = '...' > EMAIL_HOST_PASSWORD = '...' > EMAIL_USE_TLS = True > > Error: > > raise SMTPServerDisconnected("Connection unexpectedly closed") > smtplib.SMTPServerDisconnected: Connection unexpectedly closed connection to an SMTP server. One is the so-called SMTPS, which is commonly used on port 465, where the client opens a TLS tunnel right away, and all SMTP communication happens through this tunnel. The other option is STARTTLS, which is normally supported on ports 25 and 587. With this protocol, the client first opens a regular plain-text SMTP session with the server, and they exchange the STARTTLS SMTP command, after which they perform the TLS handshake, and only then is everything transferred over a secure TLS tunnel. Django supports both protocols, however, these days SMTPS is considered obsolete by some people, and a lot of folks will tell you that STARTTLS is the way to go. You set EMAIL_USE_TLS to True in your config, this tells Django to use the STARTTLS protocol, but you also set it to connect to a port on the server where it expects the SMTPS protocol instead. If you want to use SMTPS (which is what you need to do in order to connect to port 465 successfully), you need to set EMAIL_USE_TLS to False, and instead set EMAIL_USE_SSL to True. The other option is, as Raffaele suggested in another reply, to keep using EMAIL_USE_TLS, and switch the port to 587. Good luck, Michal -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/20160329073417.GH25061%40koniiiik.org. For more options, visit https://groups.google.com/d/optout. |
In reply to this post by Neto
Thanks guys, 587 worked
-- Em segunda-feira, 28 de março de 2016 21:56:12 UTC-3, Neto escreveu:
You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8f5643f4-043a-4233-a0c3-2ca9c05a3a33%40googlegroups.com. For more options, visit https://groups.google.com/d/optout. |
In reply to this post by Michal Petrucha-3
Good explanation, Michal! Thanks!
--Fred
Fred Stluka -- [hidden email] -- http://bristle.com/~fred/ Bristle Software, Inc -- http://bristle.com -- Glad to be of service! Open Source: Without walls and fences, we need no Windows or Gates. On 3/29/16 3:34 AM, Michal Petrucha
wrote:
On Mon, Mar 28, 2016 at 05:56:12PM -0700, Neto wrote:I'm trying to send emails with Amazon SES, but when I use default EMAIL_BACKEND raise error: Config: EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' # this is default EMAIL_HOST = 'email-smtp...amazonaws.com' EMAIL_PORT = 465 EMAIL_HOST_USER = '...' EMAIL_HOST_PASSWORD = '...' EMAIL_USE_TLS = True Error: raise SMTPServerDisconnected("Connection unexpectedly closed") smtplib.SMTPServerDisconnected: Connection unexpectedly closedThe problem is that there are two different ways of establishing a TLS connection to an SMTP server. One is the so-called SMTPS, which is commonly used on port 465, where the client opens a TLS tunnel right away, and all SMTP communication happens through this tunnel. The other option is STARTTLS, which is normally supported on ports 25 and 587. With this protocol, the client first opens a regular plain-text SMTP session with the server, and they exchange the STARTTLS SMTP command, after which they perform the TLS handshake, and only then is everything transferred over a secure TLS tunnel. Django supports both protocols, however, these days SMTPS is considered obsolete by some people, and a lot of folks will tell you that STARTTLS is the way to go. You set EMAIL_USE_TLS to True in your config, this tells Django to use the STARTTLS protocol, but you also set it to connect to a port on the server where it expects the SMTPS protocol instead. If you want to use SMTPS (which is what you need to do in order to connect to port 465 successfully), you need to set EMAIL_USE_TLS to False, and instead set EMAIL_USE_SSL to True. The other option is, as Raffaele suggested in another reply, to keep using EMAIL_USE_TLS, and switch the port to 587. Good luck, Michal -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/56FB05CF.4060603%40bristle.com. For more options, visit https://groups.google.com/d/optout. |
In reply to this post by Neto
This exception is raised when the server unexpectedly disconnects, or when an attempt is made to use the python mail SMTP instance before connecting it to a server. Clients sending outgoing mail should connect on port 587 and use starttls. To use port 465, you need to call smtplib.SMTP_SSL(). Currently, it calls smtplib.SMTP() .. so,change your PORT from 465 into 587 it. Also, you'll need to send the ehlo command before the starttls command, then again after the starttls command. On Tuesday, March 29, 2016 at 6:26:12 AM UTC+5:30 Neto wrote:
You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/fa4563f7-e0bf-4803-8b3c-e4bf26e706f4n%40googlegroups.com. |
Free forum by Nabble | Edit this page |