smtplib.SMTPRecipientRefused发送emai时出错

2024-04-25 02:14:19 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

收到错误:

^{pr2}$

以下错误的原因是什么?如何解决?已经坚持了好几个小时了!!! PS:我的端口25正常工作,我使用的是Python2.7.9和Ubuntu15.04


Tags: totextservertypemsgfilesassertmultiple