发送电子邮件时smtplib.SMTPRecipientRefused错误

时间:2016-07-15 20:08:47

标签: python email smtplib

我有基本电子邮件代码,如下所示:

#sendmail function to send multiple attachments to multiple users at the   same time 
def sendMail(to, fro, subject, text, files=[], server="localhost"):
    assert type(to) == list
    assert type(files) == list
    msg = MIMEMultipart()
    msg['From'] = fro
    msg['To'] = COMMASPACE.join(to)
    msg['Date'] = formatdate(localtime=True)
    msg['Subject'] = subject
    msg.attach(MIMEText(text, 'html'))
#    print "Obtained Files:",files

    for file in files:
        part = MIMEBase('application', "octet-stream")
        part.set_payload(open(file.strip(' '), "rb").read())
        Encoders.encode_base64(part)
        part.add_header('Content-Disposition', 'attachment; filename="%s"'
                       % os.path.basename(file))
        msg.attach(part)
    smtp = smtplib.SMTP(server)
    smtp.sendmail(fro, to, msg.as_string())
    smtp.close()

我收到的错误:

smtplib.SMTPRecipientsRefused: {'firstname.lastname@work.com': (553, '5.5.4 <firstname.lastname@work.com>... Domain name required for sender address a.b@work.com')}

以下错误的原因是什么?如何解决?好几个小时以来一直坚持这个! PS:我的端口25工作正在使用python 2.7.9和Ubuntu 15.04

0 个答案:

没有答案