如何用python发html和plain text格式的邮件

import smtplib
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart


smtp_sever = smtplib.SMTP('smtp_host')

msgRoot = MIMEMultipart('related')
msg['From'] = sender
msg['To'] = recepient
msg['Subject'] = 'Hello'

msgAlernative = MIMEMultipart('alernative')
msgRoot.attach(msgAlernative)

html="<html><body>Hello world</body></html>
msgHtml = MIMEText(html, 'html')   
msgAlernative.attach(msgHtml)

text = 'Hello world'
msgTxt = MIMEText(text)
msgAlernative.attach(msgTxt)

smtp_server.sendmail(sender, recepient, msgRoot.as_string())

 

 

 

 

你可能感兴趣的:(html,python)