n/chit-chatu/guguan123 · 7 个月前
注册 登录
n/chit-chat · 7 个月前 · 已编辑 · 265 次浏览
u/guguan123铂金

写了个脚本,在301Mail有新邮件时用Telegram通知

301Mail: https://6waed6lo6phn6.pages.dev/t/topic/81120

感谢 @free1 大佬的免费邮箱,但是不支持客户端而且收到邮件没有通知还是比较难受。
F12粗略看了一下Cloud Mail的API,还挺简单,就写了一个小脚本在有新邮件的时候用Telegram通知我。

或许有其他人也需要,就在此分享出来(理论上用Cloud Mail的邮箱应该都兼容,改一下邮箱API地址就行了)

https://github.com/guguan123/301mail-tgbot

使用方法

编译方法

gcc -o 301mail_tgbot main.c \
    -lcurl -lcjson -lgumbo \
    -DACCOUNT_ID=<邮箱的accountId> \
    -DAUTH_TOKEN='"<邮箱的Authorization请求头内容>"' \
    -DTG_URL='"https://api.telegram.org/bot<YOUR_BOT_TOKEN>/sendMessage"' \
    -DTG_CHAT_ID='"<你的Telegram账户ID>"'

示例

登陆 https://301333.xyz 并打开浏览器开发者工具
图片
图片对应填写的信息👇(Telegram Bot相关的教程很多,这里就不展开了,其中的TG_CHAT_ID可以在@kinhrobot输入/id获取到)

gcc -o 301mail_monitor main.c \
    -lcurl -lcjson -lgumbo \
    -DACCOUNT_ID=39 \
    -DAUTH_TOKEN='"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjM5LCJ0b2tlbiI6IjcxZGZkZTYxLTJlNWItNGYxYS1hNWI1LWY0M2VmZjYwMmJhOSIsImlhdCI6MTc3NjIwNDk2N30.aJ9edXyYmnmMlTDvngnCLQqiNXndWxxs1MAB48xK-SI"' \
    -DTG_URL='"https://api.telegram.org/bot4839574812:AAFD39kkdpWt3ywyRZergyOLMaJhac60qc/sendMessage"' \
    -DTG_CHAT_ID='"6524442943"'

将编译好的程序扔到服务器的 /etc/periodic/15min 目录,让cron隔一段时间自动运行一次;或者设置一个systemd timer,定时运行就好了

有新邮件的时候就会发送通知
图片

Cloud Mail的API用法,不感兴趣可以忽略

检查新邮件的API是:

https://301333.xyz/api/email/latest?emailId=0&accountId=39&allReceive=0

其中的emailId参数是上一次收取到的新邮件的偏移量,每手动一封新邮件+1;
accountId参数是用户ID,固定的;
allReceive不知道有啥用...

只需要带上用于身份验证的Authorization请求头,就可以GET请求这个API端点来接收新邮件

API响应内容也挺简单

没收到邮件的响应内容固定是:

{"code":200,"message":"success","data":[]}

code固定是200,data就是空数组

如果收到了新邮件,就会往data数组里填对象

文本类型:

{
	"code": 200,
	"message": "success",
	"data": [{
		"emailId": 251,
		"sendEmail": "[email protected]",
		"name": "GuGuan123",
		"accountId": 39,
		"userId": 39,
		"subject": "Hello",
		"text": "This is a text mail\n",
		"content": "",
		"cc": "[]",
		"bcc": "[]",
		"recipient": "[{\"address\":\"[email protected]\",\"name\":\"\"}]",
		"toEmail": "[email protected]",
		"toName": "",
		"inReplyTo": "",
		"relation": "",
		"messageId": "<[email protected]>",
		"type": 0,
		"status": 0,
		"resendEmailId": null,
		"message": null,
		"unread": 0,
		"createTime": "2026-04-15 14:52:43",
		"isDel": 0,
		"attList": []
	}]
}

HTML类型:

{
	"code": 200,
	"message": "success",
	"data": [{
		"emailId": 252,
		"sendEmail": "[email protected]",
		"name": "GuGuan123",
		"accountId": 39,
		"userId": 39,
		"subject": "Hello",
		"text": null,
		"content": "<!DOCTYPE html><html lang=\"en\"><body><p>This is a HTML mail</p></body></html>\n",
		"cc": "[]",
		"bcc": "[]",
		"recipient": "[{\"address\":\"[email protected]\",\"name\":\"\"}]",
		"toEmail": "[email protected]",
		"toName": "",
		"inReplyTo": "",
		"relation": "",
		"messageId": "<[email protected]>",
		"type": 0,
		"status": 0,
		"resendEmailId": null,
		"message": null,
		"unread": 0,
		"createTime": "2026-04-15 14:52:57",
		"isDel": 0,
		"attList": []
	}]
}

如果Token失效:

{"code":401,"message":"身份认证失效,请重新登录"}
3
3
登录后参与讨论。

3 条回复

排序
  1. James 💯 传奇 MANAGER 7 个月前

    谢谢分享,挺有用的。

    0
  2. Arvin_Leung 3 YEARS 7 个月前

    这个不错哦。看看怎么使用。

    0
  3. free1 白银 不离不弃 7 个月前

    你才是大佬

    0