python编辑邮件格式_python发送邮件模板
python發(fā)送郵件(不帶附件)模板
import smtplib
from email.mime.text import MIMEText
from email.header import Header
sender = 'xxxxxxxxx@163.com'
receiver = 'xxxxxx@126.com'
subject = '報警'
username = 'xxxxxxxx@163.com'
password = 'xxxx'
msg = MIMEText(strs, 'plain', 'utf-8')
msg['Subject'] = Header(subject, 'utf-8')
msg['From'] = 'Tim'
msg['To'] = "lizhao_dc@126.com"
smtp = smtplib.SMTP()
smtp.connect('smtp.163.com')
smtp.login(username, password)
smtp.sendmail(sender, receiver, msg.as_string())
smtp.quit()
python發(fā)送郵件(帶附件) 模板
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
USER = '1840000XXX@163.com'
PASSWORD = 'XXXXXXXXX'
# 如名字所示: Multipart就是多個部分
msg = MIMEMultipart()
HOST = 'smtp.163.com'
msg['subject'] = 'test email from python'
msg['to'] = 'XXX@126.com'
msg['from'] = '1840000XXX@163.com'
text = MIMEText('我是純文本')
msg.attach(text)
#添加附件1
xlsxpart = MIMEApplication(open('test1.xlsx', 'rb').read())
xlsxpart.add_header('Content-Disposition', 'attachment', filename='test1.xlsx')
msg.attach(xlsxpart)
#添加附件2
xlsxpart2 = MIMEApplication(open('test2.xlsx', 'rb').read())
xlsxpart2.add_header('Content-Disposition', 'attachment', filename='test2.xlsx')
msg.attach(xlsxpart2)
#開始發(fā)送郵件
client = smtplib.SMTP()
client.connect(HOST)
client.login(USER, PASSWORD)
client.sendmail('1840000XXXX@163.com', ['XXXX@126.com'], msg.as_string())
client.quit()
print('發(fā)送成功........')
總結
以上是生活随笔為你收集整理的python编辑邮件格式_python发送邮件模板的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 安卓抓包软件_Packet Captur
- 下一篇: 未能初始化appscan应用程序现在将关