源码
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
"""
@File : 发邮件.py
@Time : 2022-08-16 16:27
@Author : 坐公交也用券
@Version : 1.0
@Contact : faith01238@hotmail.com
@Homepage : https://liumou.site
@Desc : 当前文件作用
"""
import zmail
from loguru import logger as lger
def send(user, passwd, to_list, mess, title="你有一封新的邮件!"):
"""
发送邮件
:param title: 邮件主题
:param mess: 邮件文本内容
:param user: 登录用户
:param passwd: 登录密码
:param to_list: 收件人
:return:
"""
mes = {
'subject': title,
'content_text': str(mess)
}
try:
server = zmail.server(username=user,
password=passwd)
lger.info('登录成功')
try:
server.send_mail(recipients=to_list, mail=mes)
lger.info('发送成功')
except Exception as e:
lger.error(e)
except Exception as e:
lger.error(e)
send(user='login_user',
passwd='login_passwd',
to_list=['get@qq.com'],
mess='这是一个测试',
title='测试邮件-')
效果