2012-01-19 51 views
0

我寫了一個python腳本來發送郵件,代碼如下:蟒蛇SMTP的sendmail使用TLS - 無法

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')** 

我怎麼可能要解決這個問題嗎? 謝謝

回答

5

嗯,我認爲錯誤說明了這一切?您使用綁定到電子郵件地址的憑據。但是你的FROM變量是不同的,那麼你的賬戶應該是這樣的。像過去一樣,你今天通常不能使用任何電子郵件地址作爲發件人。

如果您認爲這不是事實。你檢查過拼寫嗎?

+0

同意@ Niclas的回答。如果您使用真實的電子郵件客戶端(例如Thunderbird)使用相同的憑證,那麼會發生什麼情況? –

+1

這個問題就像是一歲:) –