【问题标题】:SMTP sending mail failureSMTP发送邮件失败
【发布时间】:2015-08-27 01:25:31
【问题描述】:

我有一个来自here 的简单 SMTP 邮件示例,我对其进行了修改。我的代码是:

import smtplib
sender = 'igor.savinkin@gmail.com'
receivers = ['igor.savinkin@gmail.com']
message = """From: From Igor <igor.savinkin@gmail.com>
To: To Igor Savinkin <igor.savinkin@gmail.com>
Subject: SMTP e-mail test
This is a test e-mail message from SMTP python.
"""

try:
   smtpObj = smtplib.SMTP('localhost')
   smtpObj.sendmail(sender, receivers, message)         
   print "Successfully sent email to " + receivers.__str__()
except SMTPException:
   print "Error: unable to send email"

输出是:

已成功发送电子邮件至 ['igor.savinkin@gmail.com']

然而,实际上我在收件箱中没有找到类似的邮件。垃圾邮件文件夹也被检查了! 怎么了?我使用 rhc (OpenShift) 平台。

【问题讨论】:

  • 它在普通的 linux 服务器上为我工作
  • 由于您使用的是更受限制的环境(openshift),可能 smtp 端口 25 被阻止。检查 iptables。
  • 我使用了except Exception,e: 并打印出来。显示[Errno 10061] No connection could be made because the target machine actively refused it 我的是一台windows 机器
  • @duck,我在哪里/如何检查 iptables?
  • 我进行了更多搜索并成功通过Gmail help发送邮件

标签: python email sendmail


【解决方案1】:

您将邮件发送到本地 SMTP 服务器 (smtpObj = smtplib.SMTP('localhost'))。恕我直言,它接受它(请求在语法上是正确的),但随后不允许(或未配置)将其转发到 gmail。我没有使用 OpenShift,所以我不知道那里的 SMTP 是如何配置的。

您应该控制本地 SMTP 服务器的配置方式。

【讨论】:

  • 很可能是这样
猜你喜欢
  • 2014-10-26
  • 1970-01-01
  • 2017-02-09
  • 2015-11-20
  • 2023-03-10
  • 2012-11-10
  • 2013-09-01
  • 2011-12-10
  • 2019-03-01
相关资源
最近更新 更多