0
我試圖使用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"] = "[email protected]"
msg["To"] = "[email protected]"
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>
看看:msg = MIMEText(「%s」,body)'在做什麼(即想想字符串插值) –
@JonClements - 謝謝,它應該是msg = MIMEText(「%s」%body ) – user1934146
@JonClements - 現在看到身體沒有得到解碼的HTML格式..身體正在打印原樣...更新問題相同 – user1934146