真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

發(fā)郵件

發(fā)郵件:https://www.cnblogs.com/hudieren/p/.html

創(chuàng)新互聯(lián)建站是少有的網(wǎng)站設計、成都網(wǎng)站建設、營銷型企業(yè)網(wǎng)站、成都微信小程序、手機APP,開發(fā)、制作、設計、賣友情鏈接、推廣優(yōu)化一站式服務網(wǎng)絡公司,成立于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ā)件人郵箱密碼(當時申請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: 郵件服務器地址
"""
        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()
# 括號里的對應發(fā)件人郵箱昵稱、發(fā)件人郵箱賬號
        msg['From'] = formataddr([self.sender_name, self.sender])
# 括號里的對應收件人郵箱昵稱、收件人郵箱賬號
        msg['To'] = formataddr([self.attn_name, self.attn])
# 郵件的主題,也可以說是標題
        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服務器,端口是465
        # server = smtplib.SMTP_SSL("smtp.qq.com", 465)
        server = smtplib.SMTP_SSL(self.server, 465)

# 括號中對應的是發(fā)件人郵箱賬號、郵箱密碼
        server.login(self.sender, self.sender_token)
# 括號中對應的是發(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)

本文名稱:發(fā)郵件
分享網(wǎng)址:http://weahome.cn/article/dsogcec.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部