【问题标题】:TurboMail not adding Content-ID when embedding imagesTurboMail 嵌入图像时未添加 Content-ID
【发布时间】:2012-06-26 08:01:47
【问题描述】:

我的错。邮戳显然不支持内联图像。通过更改 smtp-mail 提供商解决。

我正在尝试使用 pylons 通过 TurboMail 发送电子邮件。

一切正常,除了在 html-content 中使用嵌入的图像。似乎每张图片的 Content-ID 标头都在途中丢失了。

这是我的代码:

def sendMail(to,subject,html_content,plain_content,images):
    from turbomail import Message as Mail
    mail = Mail(to=to,subject=subject)
    mail.plain = plain_content
    mail.rich = html_content

    for cid,path in images.iteritems():
        mail.embed(path,cid)

    mail.send()

在我的测试中,html 内容是:

<html>
  <header/>
  <body>
  <h1>Send images using TurboMail</h1>
  <img src="cid:img0" />
 </body>
</html>

还有图片字典:

{"img0":"path/to/img0"}

【问题讨论】:

  • 你使用的是绝对路径吗?
  • 是的,我使用的是绝对路径,并且图像按照应有的方式附加到邮件中。

标签: python email sendmail pylons embedding


【解决方案1】:

当您同时传入文件名和 cid 时,TurboMail 忽略 cid 并使用文件的基本名称。我怀疑你的文件名有扩展名,而你的 cids 没有:

{"img0":"path/to/img0.png"}

如果是这样,图像将嵌入 cid img0.png

您可以传入一个打开的图像文件; TurboMail 将不会忽略该名称:

def sendMail(to,subject,html_content,plain_content,images):
    from turbomail import Message as Mail
    mail = Mail(to=to,subject=subject)
    mail.plain = plain_content
    mail.rich = html_content

    for cid,path in images.iteritems():
        mail.embed(open(path, 'rb'), cid)

    mail.send()

我会改用marrow.mailer;它是同一个包的新名称,但 .embed 方法在处理嵌入式图像和 cid 时变得更加理智。

这个答案的早期版本混淆了骨髓和 TurboMail,而是指骨髓.embed 签名。

【讨论】:

  • 我的文件没有任何扩展名。我已经尝试了上面的建议,但似乎仍然缺少 Content-ID。这是在 gmail 中收到的标题:Content-Type: image/png; name="img0" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="img0" 我将尝试更改为骨髓邮件,看看它是否效果更好:)
  • 查看 TurboMail 3.0.3 源代码,Content-ID 标头总是生成。你用的是什么版本?
  • 我使用的是 3.0.3,你是对的,Content-ID 总是在 embed 方法中生成的。很奇怪,因为邮件到达时没有 Content-ID。
  • 运行python -m smtpd -n -c DebuggingServer localhost:8025 来创建一个调试SMTP 服务器,它会回显到标准输出您发送给它的任何电子邮件(不要忘记配置您的网络服务器以在那里发送邮件)。它应该向您显示发送的完整邮件正文以帮助调试。
  • 根据 smtp-server 的输出,Content-ID 在那里。接下来是尝试骨髓.mailer。
【解决方案2】:

显然,Postmarkapp 不支持内嵌图片。

【讨论】:

    猜你喜欢
    • 2013-04-28
    • 1970-01-01
    • 2015-06-29
    • 1970-01-01
    • 1970-01-01
    • 2013-08-02
    • 1970-01-01
    • 2022-08-03
    • 2013-08-11
    相关资源
    最近更新 更多