pythonでhtml形式のメールを送信する方法

449 ワード

import smtplib
from email.MIMEText import MIMEText

smtp_server = smtplib.SMTP(smtp_host)

html='<html><body>hello world</body></html>'
msg = MIMEText(html, 'html')
msg['From'] = sender
msg['To'] = recipient
msg['Subject'] = 'hello'

smtp_server.set_debuglevel(1) #output debug log

smtp_server.sendmail(sender, recipient, msg.as_string())