【问题标题】:Image sent from flask mail can't be visualized从烧瓶邮件发送的图像无法可视化
【发布时间】:2020-11-17 00:06:10
【问题描述】:

我有一个使用FlaskFlask-mail 的应用程序。我正在尝试发送附有图片的电子邮件。此图像是通过html 中的表单从用户发送的。电子邮件到达,但在电子邮件中打开时无法显示图像。

我的代码是:

if request.method == 'POST':
            file = request.files['arch']
            if request.files['arch'].filename != '':
                if file and allowed_file(file.filename):
                    filename = secure_filename(file.filename)
                    file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

                    fic = open( "uploads/" + file.filename, "r", encoding='utf8', errors='ignore')

                    msg.attach("uploads/" + file.filename, "image/png", fic.read())

        mail.send(msg)

对于 html:

<form action="/form" method="POST" enctype="multipart/form-data">
    <input type="file" name="arch" accept="image/*" class="arch">
</form>

【问题讨论】:

    标签: python html email flask flask-mail


    【解决方案1】:

    fic 行开始尝试以下更改。

    with app.open_resource(UPLOAD_FOLDER) as test:
            msg.attach(UPLOAD_FOLDER, 'image/jpg', test.read())
        mail.send(msg)
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-26
      相关资源
      最近更新 更多