发送电子邮件问题 - Google Compute Engine VM

时间:2016-08-30 08:21:18

标签: python django google-compute-engine

我正在尝试从python代码发送电子邮件。在我的本地服务器上测试时,代码工作正常。但是,当我在Google Compute Engine VM上部署这些更改时,电子邮件发送将停止,连接错误将开始。

错误追踪:

File "/usr/local/lib/python2.7/dist-packages/django/core/mail/message.py", line 342, 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 100, in send_messages
    new_conn_created = self.open()
  File "/usr/local/lib/python2.7/dist-packages/django/core/mail/backends/smtp.py", line 58, in open
    self.connection = connection_class(self.host, self.port, **connection_params)
  File "/usr/lib/python2.7/smtplib.py", line 256, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib/python2.7/smtplib.py", line 316, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/lib/python2.7/smtplib.py", line 291, in _get_socket
    return socket.create_connection((host, port), timeout)
  File "/usr/lib/python2.7/socket.py", line 571, in create_connection
    raise err
error: [Errno 110] Connection timed out

代码:

from django.core.mail import EmailMessage

msg = EmailMessage("Test Sub", "Msg", "abc@abc.in", ["def@abc.in"])
msg.content_subtype = "html"
msg.send()

settings.py文件中的电子邮件设置:

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.zoho.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'abc@abc.in'
EMAIL_HOST_PASSWORD = 'abcxxxabc'
DEFAULT_FROM_EMAIL = 'abc@abc.in'
DEFAULT_TO_EMAIL = 'def@abc.in'

有人可以建议这种行为的原因是什么?这个问题怎么解决?

谢谢,

1 个答案:

答案 0 :(得分:1)

您无法直接从Google云端发送邮件,端口587被阻止。你将不得不寻找另一种解决方案;看看Mailgun。