【问题标题】:Python - smtp requires authentication [closed]Python - smtp 需要身份验证 [关闭]
【发布时间】:2012-12-21 05:16:11
【问题描述】:

我正在尝试使用 python 发送电子邮件,但尽管我使用的是本地 SMTP 服务器,但它似乎需要身份验证。我运行的代码和我得到的错误可以在下面看到。我使用端口 587,因为无法在我的服务器上打开端口 25。您能帮我在端口 587 上使用 python 设置本地 SMTP 服务器吗?

>>> import smtplib
>>> from email.mime.text import MIMEText
>>> msg = MIMEText('Test body')
>>> me = 'support@mywebsite.com'
>>> to = 'myemail@gmail.com'
>>> msg['Subject'] = 'My Subject'
>>> msg['From'] = me
>>> msg['To'] = to
>>> s = smtplib.SMTP('localhost', 587)
>>> s.sendmail(me, [to], msg.as_string())

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/smtplib.py", line 722, in sendmail
    raise SMTPSenderRefused(code, resp, from_addr)
smtplib.SMTPSenderRefused: (530, '5.7.0 Authentication required', 'support@mywebsite.com')

【问题讨论】:

  • 是的,端口 587 需要身份验证。你有问题吗?
  • 有什么方法可以找到端口 587 的正确身份验证信息吗?
  • 是的,请联系服务器管理员。

标签: python email authentication smtp smtplib


【解决方案1】:

那么在你尝试使用s.sendmail之前,你使用s.login('user', 'password') - http://docs.python.org/2/library/smtplib.html#smtplib.SMTP.login

如果您没有登录详细信息 - 请咨询您的系统管理员。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-27
    • 2015-04-29
    • 2012-09-04
    相关资源
    最近更新 更多