python發送html格式的table數據(帶認證,587端口)

python發送html格式的table數據(帶認證,587端口)html

vi mailtable.py

#!/usr/bin/pythonpython

-- coding:UTF-8 --

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.header import Headeride

smtpserver='smtp.ming.com'ui

username='ming.yang@ming.com'server

password='xxxxxx'htm

sender='ming.yang@ming.com'ip

receiver = ['zhi.yang@ming.com','zhi2.yang@ming.com']utf-8

subject='aa'string

msg=MIMEMultipart('mixed')it

msg['Subject']=subject

msg['From']='ming.yang@ming.com'

msg['To']=";".join(receiver)

html="""
<html>
<head></head>
<body>
<table border="1">
<tr>
<th>1</th>
<th>2</th>
</tr>
<td>aa</td>
<td>bb</td>
</tr>
</table>
</body>
</html>
"""

text_html=MIMEText(html,'html','utf-8')
msg.attach(text_html)

smtp=smtplib.SMTP()
smtp.connect('smtp.ming.com',587)
smtp.starttls()
smtp.login(username,password)
smtp.sendmail(sender,receiver,msg.as_string())
smtp.quit()

:wq

執行

python mailtable.py

相關文章
相關標籤/搜索