python 课程笔记
import smtplib
from email.mime.text import MIMEText
server = smtplib.SMTP()
server.connect('smtp.163.com', '25')
server.login('pythonstudy890', 'pyclass123')
msg = MIMEText("""
this is python_class smtplib auto send mail!!
<table>
<tr style="background-color: red"><td>系统类型</td><td>PV</td><td>UV</td></tr>
<tr><td>ios</td><td>200</td><td>180</td></tr>
<tr><td>android</td><td>100</td><td>30</td></tr>
</table>
""", 'html', 'utf-8')
msg['From'] = '866852@qq.com'
msg['To'] = 'pythonstudy890@163.com'
msg['Subject'] = 'auto send mail daily!!'
server.sendmail('pythonstudy890@163.com', 'pythonstudy890@163.com', msg.as_string())
server.quit()
import smtplib
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
server = smtplib.SMTP()
server.connect('smtp.163.com', '25')
server.login('pythonstudy890', 'pyclass123')
part = MIMEMultipart()
msg = MIMEText("""
this is python_class smtplib auto send mail!!
<table>
<tr style="background-color: red"><td>系统类型</td><td>PV</td><td>UV</td></tr>
<tr><td>ios</td><td>200</td><td>180</td></tr>
<tr><td>android</td><td>100</td><td>30</td></tr>
</table>
""", 'html', 'utf-8')
fileName = MIMEApplication(open('demo1.py', 'rb').read())
fileName.add_header('content-disposition', 'attachment', filename='xxx.py')
part.attach(msg)
part.attach(fileName)
part['From'] = '866852@qq.com'
part['To'] = 'pythonstudy890@163.com'
part['Subject'] = 'smtp mulitpart'
server.sendmail('pythonstudy890@163.com', 'pythonstudy890@163.com', part.as_string())
server.quit()