Wednesday, November 11, 2020

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

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

No comments:

Post a Comment