Django throws this error: SMTPException: STARTTLS

2019-06-24 09:53发布

Due to limitation of outgoing mail in gmail, I installed exim4 on one of my server with the following settings:

dc_eximconfig_configtype='internet'
dc_other_hostnames='mydomain.com, localhost, localhost.localdomain, mail.mydomain.com'
dc_local_interfaces=''
dc_readhost='mydomain.com'
dc_relay_domains=''
dc_minimaldns='false'
dc_relay_nets=''
dc_smarthost='mydomain.com'
CFILEMODE='644'
dc_use_split_config='false'
dc_hide_mailname='true'
dc_mailname_in_oh='true'
dc_localdelivery='maildir_home'

I also changed my firewall settings to allow SMTP connection. Now I can send mail from this server with some command like this:

    echo "TEST" | mail -s testing user@example.com

Now I want to use this server to send mail for my another remote server say mydomain2.com. I am using django on this second server. The current settings of settings.py file are following:

EMAIL_HOST = 'mail.mydomain.com'
EMAIL_HOST_USER = 'username'  # username of one of my user on the first server
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 25
EMAIL_USE_TLS = True

When I try to send mail from this server using above settings and the following code:

from django.core.mail import send_mail
send_mail('testing','test','from@example.com',['to@example.com'])

I get the following error:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/django/core/mail/__init__.py", line 61, in send_mail
    connection=connection).send()
  File "/usr/local/lib/python2.7/dist-packages/django/core/mail/message.py", line 248, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/usr/local/lib/python2.7/dist-packages/django/core/mail/backends/smtp.py", line 85, in send_messages
    new_conn_created = self.open()
  File "/usr/local/lib/python2.7/dist-packages/django/core/mail/backends/smtp.py", line 51, in open
    self.connection.starttls()
  File "/usr/lib/python2.7/smtplib.py", line 635, in starttls
    raise SMTPException("STARTTLS extension not supported by server.")
SMTPException: STARTTLS extension not supported by server.

I think there is some problem in the settings of exim4.
So how I do solve this tls error.
Thanks in Advance.

1条回答
Anthone
2楼-- · 2019-06-24 10:47

Thanks Reto,
I installed the exim4 now on the second server and I tried your suggestion and then it was throwing error 'AUTHException:' .
So finally I figured out that I had to comment out two more lines. So now my setting.py file looks like this:

EMAIL_HOST = 'localhost'
#EMAIL_HOST_USER = 'username'  # username of one of my user on the first server
#EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 25
#EMAIL_USE_TLS = True

and Now it's working!!!
Thanks again Reto.

查看更多
登录 后发表回答