How to send html email with django with dynamic content in it?

后端 未结 7 1149
一向
一向 2020-12-04 11:09

Can anyone please help me sending html email with dynamic contents. One way is to copy the entire html code into a variable and populate the dynamic code within it in Django

7条回答
  •  生来不讨喜
    2020-12-04 11:35

    from django.core.mail import EmailMultiAlternatives
    
    subject, from_email, to = 'hello', 'from@example.com', 'to@example.com'
    text_content = 'This is an important message.'
    html_content = '

    This is an important message.

    ' msg = EmailMultiAlternatives(subject, text_content, from_email, [to] msg.attach_alternative(html_content, "text/html") msg.send()

提交回复
热议问题