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中配置相關信息。