2011-10-26 74 views
1

我使用this snippet將電子郵件圖像嵌入到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中使用電子郵件圖像嵌入作爲背景的正確方法是什麼?

在此先感謝

回答

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/

sending html mail with images not displaying in gmail

我認爲它可以爲你的問題有幫助。

+0

感謝Guillaume –

相關問題