我正在尝试使用 python 发送邮件,我将正文保存在变量“body”中我尝试使用下面的方法对其进行解密,但电子邮件的正文保持原样,html 代码没有被解码..我查看了 stackoverflow 上的其他帖子但是无法得到任何实质性的东西......哪里出了问题?
from email.mime.text import MIMEText
from subprocess import Popen, PIPE
def email (body,subject):
msg = MIMEText("%s" % body)
msg["From"] = "test@company.com"
msg["To"] = "bot@qualcomm.com"
msg["Subject"] = 'The contents of %s' % subject
p = Popen(["/usr/sbin/sendmail", "-t"], stdin=PIPE)
p.communicate(msg.as_string())
def main ():
subject="Test subject"
body = """\
<html>
<head></head>
<body>
<p>Hi!<br>
How are you?<br>
Here is the <a href="http://www.python.org">link</a> you wanted.
</p>
</body>
</html>
"""
email(body,subject)
if __name__ == '__main__':
main()
正文按原样打印如下..html 代码未解码
<html>
<head></head>
<body>
<p>Hi!<br>
How are you?<br>
Here is the <a href="http://www.python.org">link</a> you wanted.
</p>
</body>
</html>