From 2004723f3fcad7a3fc1960e84032340e081c7c44 Mon Sep 17 00:00:00 2001 From: Mizore Date: Sun, 15 Jan 2023 20:10:04 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=94=AF=E6=8C=81=20next-smtp-pro?= =?UTF-8?q?xy=20=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + script/config.lua | 12 ++++++++++- script/util_notify.lua | 47 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8693382..d8dca0a 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ - [x] [钉钉群机器人 DingTalk](https://open.dingtalk.com/document/robots/custom-robot-access) - [x] [飞书群机器人 Feishu](https://open.feishu.cn/document/ukTMukTMukTM/ucTM5YjL3ETO24yNxkjN) - [x] [企业微信群机器人 WeCom](https://developer.work.weixin.qq.com/document/path/91770) + - [x] [next-smtp-proxy](https://github.com/0wQ/next-smtp-proxy) - [x] 基站定位 - [x] 定时查询流量 - [x] 开机通知 diff --git a/script/config.lua b/script/config.lua index d883356..0433982 100644 --- a/script/config.lua +++ b/script/config.lua @@ -1,5 +1,5 @@ return { - -- 通知类型 telegram, pushdeer, bark, dingtalk, feishu, wecom + -- 通知类型 telegram, pushdeer, bark, dingtalk, feishu, wecom, next-smtp-proxy NOTIFY_TYPE = "pushdeer", -- -- telegram 通知配置, https://github.com/0wQ/telegram-notify @@ -24,6 +24,16 @@ return { -- wecom 通知配置, https://developer.work.weixin.qq.com/document/path/91770 WECOM_WEBHOOK = "", -- + -- next-smtp-proxy 通知配置, https://github.com/0wQ/next-smtp-proxy + NEXT_SMTP_PROXY_API = "", + NEXT_SMTP_PROXY_USER = "", + NEXT_SMTP_PROXY_PASSWORD = "", + NEXT_SMTP_PROXY_HOST = "smtp-mail.outlook.com", + NEXT_SMTP_PROXY_PORT = 587, + NEXT_SMTP_PROXY_FORM_NAME = "Air780E", + NEXT_SMTP_PROXY_TO_EMAIL = "", + NEXT_SMTP_PROXY_SUBJECT = "来自 Air780E 的通知", + -- -- 定时查询流量间隔, 单位毫秒, 设置为 0 关闭 QUERY_TRAFFIC_INTERVAL = 1000 * 60 * 60 * 6, -- diff --git a/script/util_notify.lua b/script/util_notify.lua index a04012a..d52b275 100644 --- a/script/util_notify.lua +++ b/script/util_notify.lua @@ -147,6 +147,51 @@ local function notifyToWeCom(msg) return http.request("POST", config.WECOM_WEBHOOK, header, json_data).wait() end +-- 发送到 next-smtp-proxy +local function notifyToNextSmtpProxy(msg) + if config.NEXT_SMTP_PROXY_API == nil or config.NEXT_SMTP_PROXY_API == "" then + log.error("util_notify.notifyToNextSmtpProxy", "未配置 `config.NEXT_SMTP_PROXY_API`") + return + end + if config.NEXT_SMTP_PROXY_USER == nil or config.NEXT_SMTP_PROXY_USER == "" then + log.error("util_notify.notifyToNextSmtpProxy", "未配置 `config.NEXT_SMTP_PROXY_USER`") + return + end + if config.NEXT_SMTP_PROXY_PASSWORD == nil or config.NEXT_SMTP_PROXY_PASSWORD == "" then + log.error("util_notify.notifyToNextSmtpProxy", "未配置 `config.NEXT_SMTP_PROXY_PASSWORD`") + return + end + if config.NEXT_SMTP_PROXY_HOST == nil or config.NEXT_SMTP_PROXY_HOST == "" then + log.error("util_notify.notifyToNextSmtpProxy", "未配置 `config.NEXT_SMTP_PROXY_HOST`") + return + end + if config.NEXT_SMTP_PROXY_PORT == nil or config.NEXT_SMTP_PROXY_PORT == "" then + log.error("util_notify.notifyToNextSmtpProxy", "未配置 `config.NEXT_SMTP_PROXY_PORT`") + return + end + if config.NEXT_SMTP_PROXY_TO_EMAIL == nil or config.NEXT_SMTP_PROXY_TO_EMAIL == "" then + log.error("util_notify.notifyToNextSmtpProxy", "未配置 `config.NEXT_SMTP_PROXY_TO_EMAIL`") + return + end + + local header = { + ["Content-Type"] = "application/x-www-form-urlencoded" + } + local body = { + user = config.NEXT_SMTP_PROXY_USER, + password = config.NEXT_SMTP_PROXY_PASSWORD, + host = config.NEXT_SMTP_PROXY_HOST, + port = config.NEXT_SMTP_PROXY_PORT, + form_name = config.NEXT_SMTP_PROXY_FORM_NAME, + to_email = config.NEXT_SMTP_PROXY_TO_EMAIL, + subject = config.NEXT_SMTP_PROXY_SUBJECT, + text = msg + } + + log.info("util_notify.notifyToNextSmtpProxy", "POST", config.NEXT_SMTP_PROXY_API, urlencodeTab(body)) + return http.request("POST", config.NEXT_SMTP_PROXY_API, header, urlencodeTab(body)).wait() +end + function util_notify.send(msg) log.info("util_notify.send", "发送通知", config.NOTIFY_TYPE) @@ -199,6 +244,8 @@ function util_notify.send(msg) notify = notifyToFeishu elseif config.NOTIFY_TYPE == "wecom" then notify = notifyToWeCom + elseif config.NOTIFY_TYPE == "next-smtp-proxy" then + notify = notifyToNextSmtpProxy else log.error("util_notify.send", "发送通知失败", "未配置 `config.NOTIFY_TYPE`") return