【问题标题】:Using email image embed as background in django在 django 中使用嵌入的电子邮件图像作为背景
【发布时间】:2011-10-26 08:07:41
【问题描述】:

我正在使用this snippet 嵌入 django 中的电子邮件图像。但我想用这张图片作为背景。 我在我的模型中使用这条线:

    img_content_id = 'standard.jpg'
    img_data = open('mypath/static/images/standard.jpg', 'rb').read()
    msg = MIMEMultipart(_subtype='related')

    body = 'cid:%s' % img_content_id
    html_content = render_to_string('email/mail.html',
                                      {'email': self.invited, 'url': url, 'current_site':current_site, 'body':body})

    msg = EmailMessage(subject, html_content, settings.DEFAULT_FROM_EMAIL, [self.invited])
    msg.content_subtype = "html"
    msg = email_embed_image(msg, img_content_id, img_data)
    msg.send()

并在模板中这样使用:

<table border="0" cellpadding="0" cellspacing="0" background="{{ body }}">

但我在邮件中有两张图片。 (一个作为随员)。在 django 中使用嵌入电子邮件图像作为背景的正确方法是什么?

提前致谢

【问题讨论】:

    标签: django


    【解决方案1】:

    我认为这更多是来自邮件客户端的问题。 你用什么邮件客户端?

    查看这些与 Hotmail 和 Outlook 相关的文章,可能会有所帮助:

    http://email.about.com/od/windowsmailtips/qt/et_inline_image.htm

    http://www.msoutlook.info/question/500

    此外,在阅读了您正在使用的 sn-p 的代码后,由于这一行,在附件中看到图像似乎是正确的:email.attach(img)

    查看 sn-p 的第一条评论,它显示了如何使用它:使用 css not a table。

    这些文章描述了两种方法(css和table):

    http://www.campaignmonitor.com/blog/post/3170/adding-background-images-to-your-email-in-two-simple-steps/

    sending html mail with images not displaying in gmail

    我认为它可以帮助解决您的问题。

    【讨论】:

      猜你喜欢
      • 2010-12-18
      • 1970-01-01
      • 2017-11-15
      • 1970-01-01
      • 1970-01-01
      • 2011-05-16
      • 1970-01-01
      • 2012-07-23
      • 2014-03-28
      相关资源
      最近更新 更多