如何通过MIMEMultipart发送电子邮件正文 [英] how to send a email body part through MIMEMultipart
本文介绍了如何通过MIMEMultipart发送电子邮件正文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是想知道MIMEMultipart是否具有任何属性,可以在其中传递我的电子邮件正文部分...只有我想出的部分是
I am just curious to know if MIMEMultipart has any attribute in it where I can pass my email body part ... Only part I have come up with is
msg = MIMEMultipart()
msg["From"] = emailfrom
msg["To"] = emailto
msg["Subject"] = "hi find the attached file"
msg.preamble = "please PFA"
有什么东西吗? like
Is there anything like
msg["Body"] = I will add a string or a text file
我用Google搜索它,发现
I googled for it and found
body = MIMEMultipart('alternative')
body.attach(MIMEText(text))
还有另一件事- MIMEMultipart('alternative')
的工作方式?它提供什么功能?
And one more thing - how does MIMEMultipart('alternative')
work? What functionality does it provide?
推荐答案
这对我有用:
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.
这篇关于如何通过MIMEMultipart发送电子邮件正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文