使用电子邮件图像嵌入作为 django 中的背景
我正在使用此片段将电子邮件图像嵌入到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 中使用电子邮件图像嵌入作为背景的正确方法是什么?
提前致谢
I'm using this snippet for email image embed in django. But I want to use this image as background.
I'm using this lines in my model:
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()
And using like this in template:
<table border="0" cellpadding="0" cellspacing="0" background="{{ body }}">
But i have two image in mail. (one as attache). What is the right way for Using email image embed as background in django?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这更多是邮件客户端的问题。
您使用什么邮件客户端?
请参阅这些与 Hotmail 和 Outlook 相关的文章,可能会有所帮助:
http:// email.about.com/od/windowsmailtips/qt/et_inline_image.htm
http://www.msoutlook.info/question/500
另外,在阅读了您的代码片段之后正在使用,由于这一行,在附件中看到图像似乎是正确的:
email.attach(img)
请参阅代码片段的第一条评论,它显示了如何使用它:使用 css 而不是桌子。
这些文章描述了两种方法(CSS 和表格):
http://www.campaignmonitor.com/blog/post/3170/adding-background-images-to-your-email-in-two-simple-steps/
发送图像未在 gmail 中显示的 html 邮件
我认为它对你的问题有帮助。
I think it is more a problem from the mail client.
What mail client do you use ?
See these articles related to Hotmail and Outlook, it might be helpful :
http://email.about.com/od/windowsmailtips/qt/et_inline_image.htm
http://www.msoutlook.info/question/500
Also after reading the code of the snippet you're using, it seems correct to see the image in attachment due to this line :
email.attach(img)
See the first comment of the snippet, it shows how to use it : using css not a table.
These articles describe the two ways to do it (css and 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
I think it can be helpful for your problem.