subject, from_email, to = '来自123的测试邮件', '[email protected]', '[email protected]'
text_content = 'welcome!'
html_content = '<p>欢迎访问<a href="http://www.baidu.com" target=blank>百度</a>,</p>'
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
msg.attach_alternative(html_content, "text/html")
msg.send()
发送HTML邮件代码如上所示,需要在setting.py中配置相关信息。