【问题标题】:Enable to connect to remote smtp启用以连接到远程 smtp
【发布时间】:2015-01-10 11:25:59
【问题描述】:

我这里有一个方便的python smtp 测试脚本。没什么特别的,只是基础。 它适用于我的所有服务器或桌面工作站。 但在一台服务器上,我无法连接到远程 smtp。相反,它总是尝试连接到本地 smtp。

from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib,string,datetime,time

MESSAGE = MIMEMultipart('alternative')
MESSAGE['subject'] = "TEST"
#MESSAGE['TO'] = to
# FOR TESTING ONLY
MESSAGE['TO'] = 'xxx@domain.com'
# FOR TESTING ONLY
MESSAGE['FROM'] = 'Me <no-reply@domain.com>'
HTML_BODY = MIMEText('<p>Hi this is a test</p>','html')
MESSAGE.attach(HTML_BODY)

server = smtplib.SMTP("gator3124.hostgator.com:587")

server.set_debuglevel(1)
server.login("username","password")
server.sendmail(MESSAGE['from'],[MESSAGE['to']],MESSAGE.as_string())
server.quit()

我执行这个脚本(当然更改用户名、密码等...)我得到以下输出:

send: 'ehlo h37-157-247-18.host.redstation.co.uk\r\n'
reply: '250-h37-157-247-18.host.redstation.co.uk Hello h37-157-247-18.host.redstation.co.uk [37.157.247.18]\r\n'
reply: '250-SIZE 52428800\r\n'
reply: '250-8BITMIME\r\n'
reply: '250-PIPELINING\r\n'
reply: '250-AUTH PLAIN LOGIN\r\n'
reply: '250-STARTTLS\r\n'
reply: '250 HELP\r\n'
reply: retcode (250); Msg: h37-157-247-18.host.redstation.co.uk Hello h37-157-247-18.host.redstation.co.uk [37.157.247.18]
SIZE 52428800
8BITMIME
PIPELINING
AUTH PLAIN LOGIN
STARTTLS
HELP
send: 'AUTH PLAIN xxxx =\r\n'
reply: '535 Incorrect authentication data\r\n'
reply: retcode (535); Msg: Incorrect authentication data

脚本尝试打开与本地计算机的连接并忽略脚本中的主机。这只发生在这台机器上。作为主持人,我可以输入我想要的,没关系。

编辑: 真正有趣的是我可以以 root 身份成功执行脚本。但作为“普通” ssh 用户,它连接到 localhost..

【问题讨论】:

    标签: python email smtp


    【解决方案1】:

    此错误常见于 cPanel 中的邮箱文件权限。需要 Root 访问权限才能更正此问题。启用 WHM -> 服务器配置 -> 调整设置中的“允许使用域所有者帐户的密码进行邮件帐户身份验证”选项时,可能会发生这种情况。禁用此选项,然后重试。

    因为您的服务器对 Internet 开放,可以接受来自世界任何地方的邮件,这也意味着世界上的任何人都可以尝试登录并作为您的电子邮件地址之一发送邮件。请注意,此更改将重定向传出 SMTP 连接,允许帐户进行直接连接,这可能会增加您的服务器被列入黑名单的机会。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-21
      • 2023-03-11
      • 1970-01-01
      • 2015-02-17
      • 1970-01-01
      • 2014-08-06
      相关资源
      最近更新 更多