MessagePush 是一个用于通过多个平台异步和同步推送消息的 Python 模块。它支持通过配置文件或直接调用接口发送消息。
✅ 邮件
✅ 微信
✅ 钉钉
✅ Bark
✅ Telegram
✅ IGot
✅ PushPlus
✅ Anpush
✅ 飞书
✅ Discord
pip install MessagePush
MessagePush 支持同步和异步的调用方式。您可以根据需要选择适合的方式进行消息发送。
您可以通过 Sender
类的同步方法发送消息到多个平台。
from message_push import Sender
def send_email():
Sender.email(
subject="测试邮件",
body="这是一封测试邮件",
to_email="[email protected]",
from_email="[email protected]",
smtp_server="smtp.example.com",
smtp_port=587,
smtp_user="[email protected]",
smtp_password="your_password"
)
send_email()
from message_push import Sender
def send_wechat_message():
Sender.wechat(
wechat_corp_id="your_corp_id",
wechat_corp_secret="your_corp_secret",
wechat_agent_id=1000002,
message="这是一条测试微信消息"
)
send_wechat_message()
from message_push import Sender
def send_dingtalk_message():
Sender.dingtalk(
webhook_url="https://oapi.dingtalk.com/robot/send?access_token=your_access_token",
message="这是一条测试钉钉消息",
secret="your_secret" # 可选
)
send_dingtalk_message()
您可以通过 Sender
类的异步方法发送消息到多个平台。
import asyncio
from message_push import Sender
async def send_email():
await Sender.email_async(
subject="测试邮件",
body="这是一封测试邮件",
to_email="[email protected]",
from_email="[email protected]",
smtp_server="smtp.example.com",
smtp_port=587,
smtp_user="[email protected]",
smtp_password="your_password"
)
asyncio.run(send_email())
import asyncio
from message_push import Sender
async def send_wechat_message():
await Sender.wechat_async(
wechat_corp_id="your_corp_id",
wechat_corp_secret="your_corp_secret",
wechat_agent_id=1000002,
message="这是一条测试微信消息"
)
asyncio.run(send_wechat_message())
import asyncio
from message_push import Sender
async def send_dingtalk_message():
await Sender.dingtalk_async(
webhook_url="https://oapi.dingtalk.com/robot/send?access_token=your_access_token",
message="这是一条测试钉钉消息",
secret="your_secret" # 可选
)
asyncio.run(send_dingtalk_message())
您可以通过 Sender
类的同步或异步方法使用配置文件发送消息到多个平台。
from message_push import Sender
def send_messages_with_config():
Sender.send_messages_with_config_sync(
config_path="config.yaml", # 或者 "config.json"
message="这是一条测试消息",
title="测试标题",
url="https://example.com"
)
send_messages_with_config()
import asyncio
from message_push import Sender
async def send_messages_with_config():
await Sender.send_messages_with_config_async(
config_path="config.yaml", # 或者 "config.json"
message="这是一条测试消息",
title="测试标题",
url="https://example.com"
)
asyncio.run(send_messages_with_config())
email:
to_email: "[email protected]"
from_email: "[email protected]"
smtp_server: "smtp.example.com"
smtp_port: 587
smtp_user: "[email protected]"
smtp_password: "your_password"
wechat:
corp_id: "your_corp_id"
corp_secret: "your_corp_secret"
agent_id: 1000002
to_user: "UserID"
dingtalk:
webhook_url: "https://oapi.dingtalk.com/robot/send?access_token=your_access_token"
secret: "your_secret" # 可选
bark:
bark_url: "https://api.day.app/your_bark_key"
telegram:
bot_token: "your_bot_token"
chat_id: "your_chat_id"
igot:
igot_key: "your_igot_key"
pushplus:
token: "your_pushplus_token"
anpush:
token: "your_anpush_token"
feishu:
webhook_url: "https://open.feishu.cn/open-apis/bot/v2/hook/your_feishu_webhook"
discord:
webhook_url: "https://discord.com/api/webhooks/your_discord_webhook"
whatsapp:
api_url: "https://graph.facebook.com/v13.0/your_phone_number_id/messages"
phone_number: "your_phone_number"
api_token: "your_api_token"
{
"email": {
"to_email": "[email protected]",
"from_email": "[email protected]",
"smtp_server": "smtp.example.com",
"smtp_port": 587,
"smtp_user": "[email protected]",
"smtp_password": "your_password"
},
"wechat": {
"corp_id": "your_corp_id",
"corp_secret": "your_corp_secret",
"agent_id": 1000002,
"to_user": "UserID"
},
"dingtalk": {
"webhook_url": "https://oapi.dingtalk.com/robot/send?access_token=your_access_token",
"secret": "your_secret"
#
可选
},
"bark": {
"bark_url": "https://api.day.app/your_bark_key"
},
"telegram": {
"bot_token": "your_bot_token",
"chat_id": "your_chat_id"
},
"igot": {
"igot_key": "your_igot_key"
},
"pushplus": {
"token": "your_pushplus_token"
},
"anpush": {
"token": "your_anpush_token"
},
"feishu": {
"webhook_url": "https://open.feishu.cn/open-apis/bot/v2/hook/your_feishu_webhook"
},
"discord": {
"webhook_url": "https://discord.com/api/webhooks/your_discord_webhook"
},
"whatsapp": {
"api_url": "https://graph.facebook.com/v13.0/your_phone_number_id/messages",
"phone_number": "your_phone_number",
"api_token": "your_api_token"
}
}