一、知识点
二、应用
1、脚本:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time :
# @Author :
# @Site :
# @File : gmail.py
# @Software: PyCharm
import os
import traceback
import smtplib
import mimetypes
from email import encoders
from email.mime.audio import MIMEAudio
from email.mime.base import MIMEBase
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from exchangelib import Account, Credentials, FaultTolerance, HTMLBody
class Mail:
def __init__(self,user = "",password="",signtxt="",host=""):
if isinstance(user, dict):
self.user = user.get("user")
self.password = user.get("password")
self.signtxt = user.get("signtxt","")
self.host = user.get("host")
elif isinstance(user, str) and user != "":
self.user = user
self.password = password
self.signtxt = signtxt
self.host = host
def send_email(self,to_list, title, content_text, attachment_list=[], cc_list="", codetype="gb2312"):
'''
to_list: 收件人列表,以逗号隔开,如:xxxx@xx.com.cn,xx@xx.com.cn
title: 邮件标题
content_text: 邮件正文
attachment_list: 邮件附件,数组列表类型,如:["c:\\test.txt"]
cc_list: 炒送人列表,以逗号隔开,跟收件人列表格式一样
codetype:附件编码,文本一般不用修改,其他多媒体格式需要修改
'''
# 初始化发件人信息
# 生成邮件体
msg = MIMEMultipart(