2

我只是在尝试访问主 smtp 服务器之前尝试发送测试消息。我正在尝试通过 django shell 发送它。

这就是我所包括的

from django.core.mail import EmailMessage
email = EmailMessage('test subject', 'test body', to=['me@me.com'])
email.send()

我尝试了其他替代方案,但外壳只是挂起,我必须按 ctrl-C 退出。这是痕迹

    send_mail('test email', 'hello world', 'me@me.com', ['me@me.com'],fail_silently=False)
^CTraceback (most recent call last):
    File "<console>", line 1, in <module>

    File "/usr/local/lib/python2.7/dist-packages/django/core/mail/__init__.py", line 62, in   send_mail
    connection=connection).send()

    File "/usr/local/lib/python2.7/dist-packages/django/core/mail/message.py", line 255, 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 88, in send_messages
    new_conn_created = self.open()

    File "/usr/local/lib/python2.7/dist-packages/django/core/mail/backends/smtp.py", line 49, in open
    local_hostname=DNS_NAME.get_fqdn())

    File "/usr/lib/python2.7/smtplib.py", line 249, in __init__
    (code, msg) = self.connect(host, port)

    File "/usr/lib/python2.7/smtplib.py", line 309, in connect
    self.sock = self._get_socket(host, port, self.timeout)

    File "/usr/lib/python2.7/smtplib.py", line 284, in _get_socket
    return socket.create_connection((port, host), timeout)

    File "/usr/lib/python2.7/socket.py", line 562, in create_connection
    sock.connect(sa)

    File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)

    KeyboardInterrupt

这是设置。

EMAIL_USE_TLS = True
EMAIL_HOST='smtp.gmail.com'
EMAIL_PORT=587
EMAIL_HOST_USER='not@myemail.com'
EMAIL_HOST_PASSWORD='notmypwd'

我已经浏览了该网站上的六篇文章和随机博客,但到目前为止没有任何效果,所以我不确定问题可能是什么。

谢谢您的帮助。

email = EmailMessage('test subject', 'test body', to=['me@me.com'])
email.send()
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: test subject
From: webmaster@localhost
To: me@me.com
Date: Tue, 09 Jul 2013 21:14:59 -0000
Message-ID: <20130709211459.7695.30351@ubuntu>

test body
4

0 回答 0