gpt4 book ai didi

python - 如何使用 Python/Django 在电子邮件中发送内联图像?

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

我正在尝试使用 Python/Django 发送包含内嵌图像的电子邮件。

Here是显示我是如何做的代码。它仍在开发中。因此,现在要做的就是发送一封虚拟电子邮件,其中嵌入了大黄蜂的图片。

但是,当我在 Gmail 收件箱中收到电子邮件时,我只看到以下基于文本的电子邮件。电子邮件的各个 Mime 部分以文本形式显示在电子邮件的有效负载中。我点击了 Gmail 中的“显示原始内容”按钮,然后剪切并粘贴了下面的整封电子邮件,以便您可以看到我收到的内容。

有人可以建议我在这里做错了什么吗?以及可能的解决方案?

Delivered-To: myemail@gmail.com
Received: by 10.58.189.196 with SMTP id gk4csp207059vec;
Mon, 17 Feb 2014 23:10:53 -0800 (PST)
X-Received: by 10.140.22.145 with SMTP id 17mr38512811qgn.0.1392707452834;
Mon, 17 Feb 2014 23:10:52 -0800 (PST)
Return-Path: <0000014443d53bd9-c1021b39-b43e-4d6f-bb55-0aff6c4b38f5-000000@amazonses.com>
Received: from a8-41.smtp-out.amazonses.com (a8-41.smtp-out.amazonses.com. [54.240.8.41])
by mx.google.com with ESMTP id j50si9661440qgf.137.2014.02.17.23.10.52
for <myemail@gmail.com>;
Mon, 17 Feb 2014 23:10:52 -0800 (PST)
Received-SPF: pass (google.com: domain of 0000014443d53bd9-c1021b39-b43e-4d6f-bb55-0aff6c4b38f5-000000@amazonses.com designates 54.240.8.41 as permitted sender) client-ip=54.240.8.41;
Authentication-Results: mx.google.com;
spf=pass (google.com: domain of 0000014443d53bd9-c1021b39-b43e-4d6f-bb55-0aff6c4b38f5-000000@amazonses.com designates 54.240.8.41 as permitted sender) smtp.mail=0000014443d53bd9-c1021b39-b43e-4d6f-bb55-0aff6c4b38f5-000000@amazonses.com
Return-Path: 0000014443d53bd9-c1021b39-b43e-4d6f-bb55-0aff6c4b38f5-000000@amazonses.com
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: Hello World3
From: My Django App <donotrespond@mydjangoapp.com>
To: myemail@gmail.com
Date: Tue, 18 Feb 2014 07:10:51 +0000
Message-ID: <0000014443d53bd9-c1021b39-b43e-4d6f-bb55-0aff6c4b38f5-000000@email.amazonses.com>
X-SES-Outgoing: 2014.02.18-54.240.8.41

Content-Type: multipart/related;
boundary="===============1003274537458441237=="
MIME-Version: 1.0

--===============1003274537458441237==
Content-Type: text/html; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

<p>Hello <img src="cid:myimage" /></p>
--===============1003274537458441237==
Content-Type: image/jpeg
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Id: <myimage>

/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxQTERUUEhIWFBUVFxcVFRQVGBUUFRcYFxUWFhQU
FRUYHCggGRolHRQVITEiJSkrLi4uFx8zODMsNygtLisBCgoKDg0OGhAQGywmICYzLDc3MCwvLCw1

<VERY LARGE PORTION SNIPPED>

BAgQIECAAIGaAsLKmnPVFQECBAgQIECAAAECBAgQIECAAIF0AsLKdCNTMAECBAgQIECAAAECBAgQ
IECAAIGaAsLKmnPVFQECBAgQIECAAAECBAgQIECAAIF0Av8HNFl0J1BnG68AAAAASUVORK5CYII=
--===============5170682983005376168==--

最佳答案

看起来你有:

multipart/related
-> text/html
-> image/jpeg

我过去在发送电子邮件时也遇到过麻烦,因为顶部部分是多部分/相关的。试试这个:

multipart/mixed
-> multipart/related
--> text/html
--> image/jpeg

此外,请确保并按如下方式设置图像的处置:

img.add_header("Content-Disposition", "inline", filename="myimage")

关于python - 如何使用 Python/Django 在电子邮件中发送内联图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21861593/

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