使用TLS的python smtp sendmail - 失败

时间:2012-01-19 09:29:06

标签: python smtp

我编写了一个python脚本来发送邮件和代码如下:

smtp = smtplib.SMTP(MYMAILSERVER, '587')
try:
    smtp.set_debuglevel(1)
    smtp.ehlo()
    if smtp.has_extn('STARTTLS'):
        smtp.starttls()
        smtp.ehlo()
        smtp.login(MYLOGINNAME, PASSWORD)
        smtp.sendmail(FROM, TO, CONTENT)
finally:
    smtp.quit()

我收到的消息如下:

......
data: (354, 'Start mail input; end with <CRLF>.<CRLF>')
send: 'From: xxxx/r/nTo: yyy/r/nSubject: this is a email from tutong/r/n/r/nJust for test and pls ignore it!~_~\r\n.\r\n'
reply: '550 5.7.1 Client does not have permissions to send as this sender\r\n'
reply: retcode (550); Msg: 5.7.1 Client does not have permissions to send as this sender
data: (550, '5.7.1 Client does not have permissions to send as this sender')
send: 'rset\r\n'
reply: '250 2.0.0 Resetting\r\n'
reply: retcode (250); Msg: 2.0.0 Resetting
send: 'quit\r\n'
reply: '221 2.0.0 Service closing transmission channel\r\n'
reply: retcode (221); Msg: 2.0.0 Service closing transmission channel
Traceback (most recent call last):
  File "mailsend.py", line 11, in <module>
    smtp.sendmail('xxxx', 'yyy', 'From: xxxx/r/nTo: yyy/r/nSubject: this is a email from tutong/r/n/r/nJust for test and pls ignore it!~_~')
  File "/usr/local/lib/python2.5/smtplib.py", line 699, in sendmail
    raise SMTPDataError(code, resp)
smtplib.SMTPDataError: (**550, '5.7.1 Client does not have permissions to send as this sender')**

我该如何解决这个问题? 感谢

1 个答案:

答案 0 :(得分:5)

嗯,我认为错误说明了一切?您使用绑定到电子邮件地址的凭据。但是你的FROM变量与你的帐户所说的不同。今天你经常不能像过去那样使用任何电子邮件地址作为发件人。

如果你认为这是事实。你检查过拼写了吗?