發(fā)郵件:https://www.cnblogs.com/hudieren/p/.html
創(chuàng)新互聯(lián)建站是少有的網(wǎng)站設(shè)計、成都網(wǎng)站建設(shè)、營銷型企業(yè)網(wǎng)站、成都微信小程序、手機APP,開發(fā)、制作、設(shè)計、賣友情鏈接、推廣優(yōu)化一站式服務(wù)網(wǎng)絡(luò)公司,成立于2013年,堅持透明化,價格低,無套路經(jīng)營理念。讓網(wǎng)頁驚喜每一位訪客多年來深受用戶好評
收郵件:https://www.cnblogs.com/hudieren/p/.html
解析郵件:https://www.cnblogs.com/hudieren/p/.html
刪除郵件:https://www.cnblogs.com/hudieren/p/.html
# -*- coding: utf-8 -*- # @Author : 107 # @File : emaildriver.py # @explain : 發(fā)郵件 import json import re import smtplib import email import time from email.mime.text import MIMEText from email.utils import formataddr from email.mime.multipart import MIMEMultipart import imaplib import os class SendEmail: def __init__(self, sender, sender_name, sender_token, attn, attn_name, subject, connect, files, server): """ :param sender: 發(fā)件人郵箱賬號 :param sender_name: 發(fā)件人郵箱昵稱 :param sender_token: 發(fā)件人郵箱密碼(當(dāng)時申請smtp給的口令) :param attn: 收件人郵箱賬號 :param attn_name: 收件人郵箱昵稱 :param subject: 主題 :param connect: 內(nèi)容 :param files: 附件,格式:{'path': '路徑', 'read': 'r', 'encoding': 'utf-8', '_charset': 'utf-8', 'name': '文件名'} :param server: 郵件服務(wù)器地址 """ self.sender= sender self.sender_name= sender_name self.sender_token= sender_token self.attn= attn self.attn_name= attn_name self.subject= subject self.connect= connect self.files= files self.server= server def accessory(self, file): """ 處理單個附件 :param file: :return: """ path= file.get('path') rea= file.get('read') e= file.get('encoding') _charset= file.get('_charset') name= file.get('name') if not name: name= os.path.split(path)[-1] if e: with open(path, rea, encoding=e) as r: connect= r.read() else: with open(path, rea) as r: connect= r.read() acc= MIMEText(connect, _charset=_charset) acc["Content-Type"] = 'application/octet-stream' # 不能兼容outlook # acc1["Content-Disposition"] = f'attachment; filename="{name}"' # 可以兼容outlook acc.add_header("Content-Disposition", "attachment", filename=("gb", "", name)) return acc def send_email(self): # connect = "這是我使用python smtplib及email模塊發(fā)送的郵件" # 正文 msg = MIMEMultipart() # 括號里的對應(yīng)發(fā)件人郵箱昵稱、發(fā)件人郵箱賬號 msg['From'] = formataddr([self.sender_name, self.sender]) # 括號里的對應(yīng)收件人郵箱昵稱、收件人郵箱賬號 msg['To'] = formataddr([self.attn_name, self.attn]) # 郵件的主題,也可以說是標(biāo)題 msg['Subject'] = self.subject # 正文 msg.attach(MIMEText(self.connect, _charset='utf-8')) # 附件 for file in self.files: acc= self.accessory(file) msg.attach(acc) # 發(fā)件人郵箱中的SMTP服務(wù)器,端口是465 # server = smtplib.SMTP_SSL("smtp.qq.com", 465) server = smtplib.SMTP_SSL(self.server, 465) # 括號中對應(yīng)的是發(fā)件人郵箱賬號、郵箱密碼 server.login(self.sender, self.sender_token) # 括號中對應(yīng)的是發(fā)件人郵箱賬號、收件人郵箱賬號、發(fā)送郵件 server.sendmail(self.sender, [self.attn, ], msg.as_string()) server.quit()# 關(guān)閉連接 def run(self): # self.send_email() try: self.send_email() return True except Exception as e: print(e.args)
文章標(biāo)題:發(fā)郵件
新聞來源:http://redsoil1982.com.cn/article42/dsogcec.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃、軟件開發(fā)、App設(shè)計、用戶體驗、網(wǎng)站維護、Google
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)