如何在 Flask 中显示电子邮件

问题描述 投票:0回答:0

我有一个自动生成和发送电子邮件的系统,然后将 MIMEMultipart 数据(作为一个字符串)保存在一个文件中。

我在 Flask 中构建的 Web 应用程序必须显示发送了哪些电子邮件,并为每封电子邮件显示该电子邮件的外观。当然,用户(主要是我自己)可以下载 MIMEFile 并在本地解压,但并不是每个用户都能学会。另一种解决方案是我在 Flask 中手动编写一个页面,提取各个部分并显示它们,包括正文(无论是文本还是 html)和附件。

我希望有更简单的方法,也许是使用烧瓶扩展,或者我错过了一些在浏览器中显示电子邮件的简单方法?

这段代码显示了我在说什么样的数据:

msg = MIMEMultipart() 
msg['From'] = '[email protected]' 
msg['To'] = '[email protected]' 
msg['Subject'] = 'test' 
msg.attach(MIMEText('Hello World!'))

part = MIMEApplication( open('map/23414234.jpg').read(), 'map.jpg') 
part['Content-Disposition'] = 'attachment; filename="%s"' % 'map.jpg' 
msg.attach(part)

emailstr = msg.as_string()
# strings like this one are logged, and I want to show the email to the user
# using such a string as input
email flask mime
© www.soinside.com 2019 - 2024. All rights reserved.