EMAIL_BACKEND doesn't works with Amazon SES!?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

EMAIL_BACKEND doesn't works with Amazon SES!?

Neto
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

If I use:
 
EMAIL_BACKEND = 'django_smtp_ssl.SSLEmailBackend'

from https://github.com/bancek/django-smtp-ssl, works right.

Code of this backend:

import smtplib
 
from django.core.mail.utils import DNS_NAME
from django.core.mail.backends.smtp import EmailBackend
 
class SSLEmailBackend(EmailBackend):
  def open(self):
   
if self.connection:
     
return False
   
try:
     
self.connection = smtplib.SMTP_SSL(self.host, self.port, local_hostname=DNS_NAME.get_fqdn())
     
if self.username and self.password:
       
self.connection.login(self.username, self.password)
     
return True
   
except:
     
if not self.fail_silently:
       
raise

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.
Reply | Threaded
Open this post in threaded view
|

Re: EMAIL_BACKEND doesn't works with Amazon SES!?

Raffaele Salmaso-2
On Tue, Mar 29, 2016 at 2:56 AM, Neto <[hidden email]> wrote:
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

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

--

--
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.
Reply | Threaded
Open this post in threaded view
|

Re: EMAIL_BACKEND doesn't works with Amazon SES!?

Michal Petrucha-3
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
The 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/20160329073417.GH25061%40koniiiik.org.
For more options, visit https://groups.google.com/d/optout.

signature.asc (836 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: EMAIL_BACKEND doesn't works with Amazon SES!?

Neto
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:
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...<a href="http://amazonaws.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Famazonaws.com\46sa\75D\46sntz\0751\46usg\75AFQjCNGHfuVpuuNfCv7P6hUcV5pxAg3-eA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Famazonaws.com\46sa\75D\46sntz\0751\46usg\75AFQjCNGHfuVpuuNfCv7P6hUcV5pxAg3-eA&#39;;return true;">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

If I use:
 
EMAIL_BACKEND = 'django_smtp_ssl.SSLEmailBackend'

from <a href="https://github.com/bancek/django-smtp-ssl" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Fbancek%2Fdjango-smtp-ssl\46sa\75D\46sntz\0751\46usg\75AFQjCNFVKSPi0Bk1A9Mf5mIfwdJ17Qzsow&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Fbancek%2Fdjango-smtp-ssl\46sa\75D\46sntz\0751\46usg\75AFQjCNFVKSPi0Bk1A9Mf5mIfwdJ17Qzsow&#39;;return true;">https://github.com/bancek/django-smtp-ssl, works right.

Code of this backend:

import smtplib
 
from django.core.mail.utils import DNS_NAME
from django.core.mail.backends.smtp import EmailBackend
 
class SSLEmailBackend(EmailBackend):
  def open(self):
   
if self.connection:
     
return False
   
try:
     
self.connection = smtplib.SMTP_SSL(self.host, self.port, local_hostname=DNS_NAME.get_fqdn())
     
if self.username and self.password:
       
self.connection.login(self.username, self.password)
     
return True
   
except:
     
if not self.fail_silently:
       
raise

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/8f5643f4-043a-4233-a0c3-2ca9c05a3a33%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: EMAIL_BACKEND doesn't works with Amazon SES!?

Fred Stluka
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 closed
The 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.
Reply | Threaded
Open this post in threaded view
|

Re: EMAIL_BACKEND doesn't works with Amazon SES!?

rahul kumar
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:
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

If I use:
 
EMAIL_BACKEND = 'django_smtp_ssl.SSLEmailBackend'

from https://github.com/bancek/django-smtp-ssl, works right.

Code of this backend:

import smtplib
 
from django.core.mail.utils import DNS_NAME
from django.core.mail.backends.smtp import EmailBackend
 
class SSLEmailBackend(EmailBackend):
  def open(self):
   
if self.connection:
     
return False
   
try:
     
self.connection = smtplib.SMTP_SSL(self.host, self.port, local_hostname=DNS_NAME.get_fqdn())
     
if self.username and self.password:
       
self.connection.login(self.username, self.password)
     
return True
   
except:
     
if not self.fail_silently:
       
raise

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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/fa4563f7-e0bf-4803-8b3c-e4bf26e706f4n%40googlegroups.com.