1 Star 0 Fork 13

feiser/pythonscript

forked from didiplus/script 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
sendEmail.py 1.45 KB
一键复制 编辑 原始数据 按行查看 历史
didiplus 提交于 2023-04-12 15:54 . 更新代码
# smtplib 用于邮件的发信动作
import smtplib
from loguru import logger
# email 用于构建邮件内容
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
# 构建邮件头
from email.header import Header
from email.mime.application import MIMEApplication
class sendEmail:
def __init__(self,maillist:list,mailtitle:str,mailcontent) -> None:
self.mail_list = maillist
self.mail_title = mailtitle
self.mail_content = mailcontent
self.mail_host = "smtp.163.com"
self.mail_user = "your email name"
self.mail_pass = "your email password"
self.mail_postfix = "163.com"
def sendMail(self,Subject,file):
me = self.mail_user + "<" + self.mail_user + "@" + self.mail_postfix + ">"
msg = MIMEMultipart()
msg['Subject'] = Subject
msg ['From'] = me
msg['To'] = ";".join()(self.mail_list)
xlsxpart = MIMEApplication(open(file, 'rb').read())
xlsxpart.add_header('Content-Disposition', 'attachment', filename=file)
msg.attach(xlsxpart)
try:
s = smtplib.SMTP() #创建邮件服务器对象
s.connect(self.mail_host) #连接到指定的smtp服务器。参数分别表示smpt主机和端口
s.login(self.mail_user, self.mail_pass) #登录到你邮箱
logger.info("登录邮箱成功")
s.sendmail(me, self.mail_list, msg.as_string()) #发送内容
s.close()
return True
except Exception as e:
return False
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/feiser/pythonscript.git
git@gitee.com:feiser/pythonscript.git
feiser
pythonscript
pythonscript
master

搜索帮助