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()
本体は次のように印刷されます。is..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>