日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

python3.5 email實現發送郵件功能

系統 1879 0

本文實例為大家分享了python3.5 email發送郵件的具體代碼,供大家參考,具體內容如下

直接套用代碼即可

            
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email import encoders
import smtplib
import time


def send_mail(subject):
 email_host = '' # 服務器地址
 sender = '' # 發件人
 password = '' # 密碼,如果是授權碼就填授權碼
 receiver = '' # 收件人

 msg = MIMEMultipart()
 msg['Subject'] = subject # 標題
 msg['From'] = '' # 發件人昵稱
 msg['To'] = '' # 收件人昵稱

 signature = '''
\n\t this is auto test report!
\n\t you don't need to follow
'''
 # text = MIMEText(signature, 'plain') # 簽名
 # msg.attach(text)

 # 正文-圖片 只能通過html格式來放圖片,所以要注釋25,26行
 mail_msg = '''

            

\n\t this is auto test report!

\n\t you don't need to follow

我的博客:

截圖如下:

''' msg.attach(MIMEText(mail_msg, 'html', 'utf-8')) # 指定圖片為當前目錄 fp = open(r'111.jpg', 'rb') msgImage = MIMEImage(fp.read()) fp.close() # 定義圖片 ID,在 HTML 文本中引用 msgImage.add_header('Content-ID', ' ') msg.attach(msgImage) ctype = 'application/octet-stream' maintype, subtype = ctype.split('/', 1) # 附件-圖片 image = MIMEImage(open(r'111.jpg', 'rb').read(), _subtype=subtype) image.add_header('Content-Disposition', 'attachment', filename='img.jpg') msg.attach(image) # 附件-文件 file = MIMEBase(maintype, subtype) file.set_payload(open(r'320k.txt', 'rb').read()) file.add_header('Content-Disposition', 'attachment', filename='test.txt') encoders.encode_base64(file) msg.attach(file) # 發送 smtp = smtplib.SMTP() smtp.connect(email_host, 25) smtp.login(sender, password) smtp.sendmail(sender, receiver, msg.as_string()) smtp.quit() print('success') if __name_- == '__main__': now = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) subject = now + '自動化測試報告' send_mail(subject)

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 屏南县| 井研县| 绥棱县| 沽源县| 镇雄县| 彭泽县| 祁连县| 马龙县| 克拉玛依市| 徐汇区| 哈巴河县| 绵阳市| 淮北市| 营口市| 冷水江市| 淅川县| 井陉县| 齐齐哈尔市| 修文县| 营口市| 磐安县| 博罗县| 堆龙德庆县| 新民市| 铜鼓县| 团风县| 巧家县| 平武县| 塔城市| 阿图什市| 晋江市| 和林格尔县| 乌兰浩特市| 建瓯市| 永吉县| 岑巩县| 通州市| 镇原县| 乐昌市| 奉化市| 阿克陶县|