5
我想发送一封电子邮件使用Python,但尽管我使用本地SMTP服务器似乎它需要身份验证。我运行的代码和我得到的错误可以在下面看到。我使用端口587,因为端口25无法在我的服务器上打开。你能帮我设置在端口587上使用Python的本地SMTP服务器吗?Python - smtp要求身份验证
>>> import smtplib
>>> from email.mime.text import MIMEText
>>> msg = MIMEText('Test body')
>>> me = '[email protected]'
>>> to = '[email protected]'
>>> 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', '[email protected]')
是的,端口587需要认证。你有问题吗? – tripleee
有没有办法找到端口587的正确认证信息? – Paris
是的,请联系服务器的管理员。 – tripleee