Django电子邮件在命令行中工作,但不在应用程序中

时间:2014-06-12 18:40:55

标签: python django exchange-server

我可以从我的服务器上的命令行获得一个简单的send_mail()来处理Django,但不能从我的应用程序中使用。使用Exchange 2010,Python 2.7.6,Django 1.6.1。

我认为这是由于Exchange上的某些设置,但为什么我可以从命令行使用它?我在这里缺少什么?

成功的命令行

Python 2.7.6 (default, Feb  5 2014, 09:30:05)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from django.core.mail import send_mail
>>> from django.conf import settings
>>> settings.configure()
>>> send_mail('test','test','email@email.com',['to@email.com'])
1

申请失败

def sg_cancellations_emails(request):
    send_mail('test', 'test', 'email@email.com', ['to@email.com'])
    return render(request, 'reports/sg/sg_cancellations_email.html')

使用应用程序时出错

Traceback (most recent call last):

  File "/sites/virtualenvs/apollo2/lib/python2.7/site-packages/django/core/handlers/base.py", line 114, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)

  File "/var/www/html/apollo2/apollo2/reports/views.py", line 156, in sg_cancellations_emails
    send_mail('test', 'test', 'email@email.com', ['to@email.com'])

  File "/sites/virtualenvs/apollo2/lib/python2.7/site-packages/django/core/mail/__init__.py", line 50, in send_mail
    connection=connection).send()

  File "/sites/virtualenvs/apollo2/lib/python2.7/site-packages/django/core/mail/message.py", line 255, in send
    return self.get_connection(fail_silently).send_messages([self])

  File "/sites/virtualenvs/apollo2/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 88, in send_messages
    new_conn_created = self.open()

  File "/sites/virtualenvs/apollo2/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 55, in open
    self.connection.login(self.username, self.password)

  File "/usr/local/lib/python2.7/smtplib.py", line 611, in login
    raise SMTPException("No suitable authentication method found.")

SMTPException: No suitable authentication method found.

0 个答案:

没有答案