gpt4 book ai didi

python - 在 Outlook 中通过电子邮件发送数据

转载 作者:太空宇宙 更新时间:2023-11-03 18:50:02 25 4
gpt4 key购买 nike

我有 HTML 代码@ http://pastie.org/8289257在一个文本文件“gerrit.txt”中,它将创建一个包含某些内容的表,我将文本文件转换为 .htm 文件并打开它输出看起来非常好,这告诉我HTML 代码很好,但是当我使用下面的代码通过电子邮件(使用 Outlook)发送它时,表格有时会变得困惑。我需要了解哪些其他方式可以发送电子邮件?我尝试过 SMTP如下所示,这似乎不起作用......

from email.mime.text import MIMEText
from smtplib import SMTP

def email (body,subject):
msg = MIMEText("%s" % body)
msg['Content-Type'] = "text/html; charset=UTF8"
msg['Subject'] = subject
s = SMTP('localhost',25)
s.sendmail('userid@company.com', ['userid2@company.com'],msg=msg.as_string())

def main ():
# open gerrit.txt and read the content into body
with open('gerrit.txt', 'r') as f:
body = f.read()
subject = "test email"
email(body,subject)
print "Done"

if __name__ == '__main__':
main()

最佳答案

您的代码完全正确,只是您需要将 html 类型传递给 MIMEText:

msg = MIMEText("%s" % body, 'html')

我已经用我的 Gmail 帐户对其进行了测试,在消息中看到了 html 代码,而没有设置 html 类型。

或者,您可以使用mailer按照建议打包 here .

关于python - 在 Outlook 中通过电子邮件发送数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18561475/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com