且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何通过MIMEMultipart发送电子邮件正文

更新时间:2022-12-03 10:15:39

这对我有用:

msg = MIMEMultipart()
msg['From'], msg['To'], msg['Subject'] = ... # specify your sender, receiver, subject attributes
body = 'This is the body of the email.'
body = MIMEText(body) # convert the body to a MIME compatible string
msg.attach(body) # attach it to your main message

您附加了正文 msg ,而 body 应该是 MIMEText 对象。

You attach the body to the msg, and body in your case should be the MIMEText object.