user1158081
user1158081

Reputation: 11

python smtp sendmail with TLS -- Failed

I wrote a python script to send a mail and the code as followed:

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()

I got the messages as followed:

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

How could I do to fix the problem? Thanks

Upvotes: 0

Views: 5141

Answers (1)

Niclas Nilsson
Niclas Nilsson

Reputation: 5901

Well, I think the error says it all? You use credentials that are bound to an e-mail adress. But your FROM variable are different then your account says it should be. You often can't today, like in the old days, use any e-mail address as sender.

If you think that this is'nt the case. Have you checked the spelling?

Upvotes: 5

Related Questions