日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python编辑邮件格式_python发送邮件模板

發布時間:2024/7/23 python 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python编辑邮件格式_python发送邮件模板 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

python發送郵件(不帶附件)模板

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發送郵件(帶附件) 模板

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)

#開始發送郵件

client = smtplib.SMTP()

client.connect(HOST)

client.login(USER, PASSWORD)

client.sendmail('1840000XXXX@163.com', ['XXXX@126.com'], msg.as_string())

client.quit()

print('發送成功........')

總結

以上是生活随笔為你收集整理的python编辑邮件格式_python发送邮件模板的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。