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