开发者社区> 问答> 正文

使用smtp从Python发送邮件,手机中无内容

我正在使用Python smtp模块发送邮件,它发送成功,并且在Outlook中看起来不错。到我签到手机时,它没有内容,只有附件。实际上内容中有三个表。有人知道如何解决此问题吗?下面是我的代码。

def send_mail(subject, sender, recipient, cc, toaddrs, body, filename):
    msg = MIMEMultipart('alternative')
    msg['Subject'] = subject
    msg['From'] = sender
    msg['To'] = ", ".join(recipient)
    msg['Cc'] = ", ".join(cc)

    message = MIMEText(body, 'html')  # html.read(), 'html')
    msg.attach(message)
    attachment = MIMEBase('application', 'octet-stream')
    attachment.set_payload(open(filename, 'rb').read())
    encoders.encode_base64(attachment)
    attachment.add_header(
        'Content-Disposition', 'attachment; filename="%s"' % os.path.basename(filename))
    msg.attach(attachment)
    smtp = smtplib.SMTP('localhost')
    smtp.sendmail(sender, toaddrs, msg.as_string())
    logger.info('Email have sent successfully!')
    smtp.quit()

任何帮助将不胜感激。谢谢。

展开
收起
几许相思几点泪 2019-12-24 21:13:15 638 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载