Django throws this error: SMTPException: STARTTLS extension not supported by server

佐手、 提交于 2019-12-13 13:14:03

问题


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:


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.



来源:https://stackoverflow.com/questions/19675093/django-throws-this-error-smtpexception-starttls-extension-not-supported-by-ser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!