2014-08-30 63 views
1

我使用django-ses後端發送django-newsletter。但收到的電子郵件不包含任何html標記。django-ses不發送html郵件

如果我django.core.mail.backends.console.EmailBackend發送,還有電子郵件,因爲我想,並與正常標題:

MIME-Version: 1.0 
Content-Type: text/html; charset="utf-8" 
Content-Transfer-Encoding: 8bit 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" 
    "http://www.w3.org/TR/html4/strict.dtd"> 

<html lang="en"> 

回答

0

設置你的電子郵件消息對象的content_subtypetext/html

msg = EmailMessage(subject, html_content, from_email, [to]) 
msg.content_subtype = "html" # Main content is now text/html 
msg.send() 

或者你可以使用EmailMultiAlternatives

from django.core.mail import EmailMultiAlternatives 

subject, from_email, to = 'hello', '[email protected]', '[email protected]' 
text_content = 'This is an important message.' 
html_content = '<p>This is an <strong>important</strong> message.</p>' 
msg = EmailMultiAlternatives(subject, text_content, from_email, [to]) 
msg.attach_alternative(html_content, "text/html") 
msg.send() 

這樣,默認情況下,電子郵件HTML將被呈現,但您仍然會有一個文本版本可以重新使用。