render_to_string:加载模板,渲染模板并返回结果string.
html_message:如果html_message提供,则默认消息替换为Html消息.
邮件/ HTML的message.html
Hi {{ first_name }}.
This is your {{ email }}
Thank you
Run Code Online (Sandbox Code Playgroud)
views.py
def mail_function(request):
subject = 'Test Mail'
from = 'info@domain.com'
to = 'to@domain.com'
c = Context({'email': email,
'first_name': first_name})
html_content = render_to_string('mail/html-message.html', c)
txtmes = render_to_string('mail/text-message.html', c)
send_mail(subject,
txtmes,
from,
[to],
fail_silently=False,
html_message=html_content)
Run Code Online (Sandbox Code Playgroud)