Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Donate
Please sign in before you donate.
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
1 Star 1 Fork 24

张张/WaitAdmin开源后台系统(Python版)

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (2)
Tags (1)
master
develop
1.0.0
master
Branches (2)
Tags (1)
master
develop
1.0.0
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (2)
Tags (1)
master
develop
1.0.0
driver.py 5.35 KB
Copy Edit Raw Blame History
zero authored 2024年09月20日 11:21 +08:00 . update: 调整描述
# +----------------------------------------------------------------------
# | WaitAdmin(fastapi)快速开发后台管理系统
# +----------------------------------------------------------------------
# | 欢迎阅读学习程序代码,建议反馈是我们前进的动力
# | 程序完全开源可支持商用,允许去除界面版权信息
# | gitee: https://gitee.com/wafts/waitadmin-python
# | github: https://github.com/topwait/waitadmin-python
# | 官方网站: https://www.waitadmin.cn
# | WaitAdmin团队版权所有并拥有最终解释权
# +----------------------------------------------------------------------
# | Author: WaitAdmin Team <2474369941@qq.com>
# +----------------------------------------------------------------------
import aiosmtplib
from aiosmtplib import SMTP
from typing import Union, List
from email.message import EmailMessage
from common.utils.config import ConfigUtil
class MailDriver:
def __init__(self, host: str = "", port: int = 25, username: str = "", password: str = "", ssl: bool = False):
self.port: int = port
self.host: str = host
self.username: str = username
self.password: str = password
self.verify_type: str = "ssl" if ssl else "default"
self.messages = EmailMessage()
async def init_config(self):
"""
初始化邮件配置
"""
if not self.host:
config = await ConfigUtil.get("email") or {}
self.port = int(config.get("smtp_port", 25))
self.host = str(config.get("smtp_host", ""))
self.username = config.get("smtp_user", "")
self.password = config.get("smtp_pass", "")
self.verify_type = config.get("verify_type", "default")
async def smtp(self):
"""
获取邮件服务连接
Warning:
连接使用完后记得把连接关闭
关闭方式: smtp_client.quit()
Author:
zero
"""
await self.init_config()
smtp_client = SMTP(
hostname=self.host,
port=self.port,
username=self.username,
password=self.password,
use_tls=True if self.verify_type == "ssl" else False
)
await smtp_client.connect()
return smtp_client
async def send(self):
"""
发送邮件消息
Raises:
RuntimeError
Author:
zero
"""
await self.init_config()
if not self.messages["From"]:
self.messages["From"] = self.username
result = await aiosmtplib.send(
self.messages,
hostname=self.host,
port=25,
username=self.username,
password=self.password,
use_tls=True if self.verify_type == "ssl" else False
)
if not result[1].startswith("Mail OK"):
raise Exception(result[1])
def subject(self, title: str):
"""
设置邮件标题
Args:
title (str): 邮件的标题。
Author:
zero
"""
self.messages["subject"] = title
return self
def body(self, body: str):
"""
设置邮件内容
Args:
body (str): 邮件文本内容。
Author:
zero
"""
self.messages.set_content(body)
return self
def add_alternative(self, body: str, subtype: str = "html"):
"""
设置HTML内容
Args:
body (str): HTML文本内容。
subtype (str): 文本类型。
Author:
zero
"""
self.messages.add_alternative(body, subtype=subtype)
return self
def add_attachment(self, path: str, filename: str, maintype: str, subtype: str):
"""
设置邮件附件
Args:
path (str): 文件的本地路径: 如: /www/aa.png。
filename (str): 文件的名称: 如: wa.png。
maintype (str): 文件的类型, 如: image。
subtype (str): 文件子类型, 如: png。
Author:
zero
"""
with open(path, "rb") as f:
data = f.read()
self.messages.add_attachment(data, maintype=maintype, subtype=subtype, filename=filename)
return self
def fromm(self, address: str):
"""
设置发件人 (发出的邮箱号)
Args:
address (Union[str, List[str]]): 发送者的邮箱。
Example:
address = "wa@qq.com"
Author:
zero
"""
self.messages["From"] = address
return self
def to(self, address: Union[str, List[str]]):
"""
设置收件人 (发送给谁?)
Args:
address (Union[str, List[str]]): 接收者的邮箱。
Example:
address = "wa@qq.com"
address = ["wa.qq.com", "wa.163.com"]
Author:
zero
"""
self.messages["To"] = address
return self
def cc(self, address: Union[str, List[str]]):
"""
设置抄送人 (抄送给谁?)
Args:
address (Union[str, List[str]]): 接收者的邮箱。
Example:
address = "wa@qq.com"
address = ["wa.qq.com", "wa.163.com"]
Author:
zero
"""
self.messages["Cc"] = address
return self
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

🔥🔥🔥WaitAdmin(python)是一款基于Fastapi+Vue3开发的一套快速开发通用管理后台,集成Vue常用组件,RBAC权限管理, 让开发变的简单,界面简洁清爽,后台支持多种菜单结构可满足不同人群的需求,非常适合二开做项目。
Cancel

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/cvbcvb/waitadmin-python.git
git@gitee.com:cvbcvb/waitadmin-python.git
cvbcvb
waitadmin-python
WaitAdmin开源后台系统(Python版)
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /