This commit is contained in:
jinnrry 2024-03-01 19:09:24 +08:00
parent 2968f9cbaa
commit eeb22b5ed3
12 changed files with 112 additions and 62 deletions

View File

@ -34,28 +34,46 @@ jobs:
- name: Setup Go environment
uses: actions/setup-go@v4.1.0
with:
go-version: '1.21'
check-latest: true
- name: Gen output name
run: echo "FILENAME=pmail_${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV}
run: |
echo "FILENAME=pmail_${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV}
echo "TGFILENAME=telegram_push_${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV}
echo "WCFILENAME=wechat_push_${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV}
echo "WEBFILENAME=web_push_${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV}
- name: Rename Windows File
if: matrix.goos == 'windows'
run: echo "FILENAME=pmail_${{ matrix.goos }}_${{ matrix.goarch }}.exe" >> ${GITHUB_ENV}
run: |
echo "FILENAME=pmail_${{ matrix.goos }}_${{ matrix.goarch }}.exe" >> ${GITHUB_ENV}
echo "TGFILENAME=telegram_push_${{ matrix.goos }}_${{ matrix.goarch }}.exe" >> ${GITHUB_ENV}
echo "WCFILENAME=wechat_push_${{ matrix.goos }}_${{ matrix.goarch }}.exe" >> ${GITHUB_ENV}
echo "WEBFILENAME=web_push_${{ matrix.goos }}_${{ matrix.goarch }}.exe" >> ${GITHUB_ENV}
- name: FE Build
run: cd fe && yarn && yarn build
- name: BE Build
run: |
cd server && cp -rf ../fe/dist http_server
go build -ldflags "-s -w -X 'main.goVersion=$(go version)' -X 'main.gitHash=$(git show -s --format=%H)' -X 'main.buildTime=$(TZ=UTC-8 date +%Y-%m-%d" "%H:%M:%S)'" -o ${{ env.FILENAME }} main.go
go build -ldflags "-s -w -X 'main.version=${{ VERSION }}' -X 'main.goVersion=$(go version)' -X 'main.gitHash=$(git show -s --format=%H)' -X 'main.buildTime=$(TZ=UTC-8 date +%Y-%m-%d" "%H:%M:%S)'" -o ${{ env.FILENAME }} main.go
go build -ldflags "-s -w" -o ${{ env.TGFILENAME }} hooks/telegram_push/telegram_push.go
go build -ldflags "-s -w" -o ${{ env.WEBFILENAME }} hooks/web_push/web_push.go
go build -ldflags "-s -w" -o ${{ env.WCFILENAME }} hooks/wechat_push/wechat_push.go
- name: Upload files to Artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ env.FILENAME }}
path: ./server/${{ env.FILENAME }}
path: |
./server/${{ env.FILENAME }}
./server/${{ env.TGFILENAME }}
./server/${{ env.WEBFILENAME }}
./server/${{ env.WCFILENAME }}
- name: Upload binaries to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ./server/${{ env.FILENAME }}
file: |
./server/${{ env.FILENAME }}
./server/${{ env.TGFILENAME }}
./server/${{ env.WEBFILENAME }}
./server/${{ env.WCFILENAME }}
tag: ${{ github.ref }}
file_glob: true

View File

@ -15,6 +15,9 @@ COPY --from=febuild /work/dist /work/http_server/dist
RUN apk update && apk add git
RUN go build -ldflags "-X 'main.goVersion=$(go version)' -X 'main.gitHash=$(git show -s --format=%H)' -X 'main.buildTime=$(TZ=UTC-8 date +%Y-%m-%d" "%H:%M:%S)'" -o pmail main.go
RUN cd /work/hooks/telegram_push && go build -ldflags "-s -W" -o output/telegram_push main.go
RUN cd /work/hooks/web_push && go build -ldflags "-s -W" -o output/web_push main.go
RUN cd /work/hooks/wechat_push && go build -ldflags "-s -W" -o output/wechat_push main.go
FROM alpine
@ -30,6 +33,8 @@ RUN apk add --no-cache tzdata \
COPY --from=serverbuild /work/pmail .
COPY --from=serverbuild /work/hooks/telegram_push/output/* ./plugin/
COPY --from=serverbuild /work/hooks/web_push/output/* ./plugin/
COPY --from=serverbuild /work/hooks/wechat_push/output/* ./plugin/
CMD /work/pmail

View File

@ -5,7 +5,10 @@ WORKDIR /work
COPY server .
RUN apk update && apk add git
RUN go build -ldflags "-X 'main.goVersion=$(go version)' -X 'main.gitHash=$(git show -s --format=%H)' -X 'main.buildTime=$(TZ=UTC-8 date +%Y-%m-%d" "%H:%M:%S)'" -o pmail main.go
RUN go build -ldflags "-s -w -X 'main.goVersion=$(go version)' -X 'main.gitHash=$(git show -s --format=%H)' -X 'main.buildTime=$(TZ=UTC-8 date +%Y-%m-%d" "%H:%M:%S)'" -o pmail main.go
RUN cd /work/hooks/telegram_push && go build -ldflags "-s -W" -o output/telegram_push main.go
RUN cd /work/hooks/web_push && go build -ldflags "-s -W" -o output/web_push main.go
RUN cd /work/hooks/wechat_push && go build -ldflags "-s -W" -o output/wechat_push main.go
FROM alpine
@ -21,6 +24,8 @@ RUN apk add --no-cache tzdata \
COPY --from=serverbuild /work/pmail .
COPY --from=serverbuild /work/hooks/telegram_push/output/* ./plugin/
COPY --from=serverbuild /work/hooks/web_push/output/* ./plugin/
COPY --from=serverbuild /work/hooks/wechat_push/output/* ./plugin/
CMD /work/pmail

View File

@ -2,9 +2,7 @@ build: build_fe build_server telegram_push web_push wechat_push package
clean:
rm -rf output
rm -rf server/hooks/telegram_push/output
rm -rf server/hooks/web_push/output
rm -rf server/hooks/wechat_push/output
build_fe:
cd fe && yarn && yarn build
@ -41,11 +39,11 @@ package: clean
mkdir output
mv server/pmail* output/
mkdir output/config
mkdir output/plugin
mkdir output/plugins
cp -r server/config/dkim output/config/
cp -r server/config/ssl output/config/
cp -r server/config/config.json output/config/
mv server/hooks/telegram_push/output/* output/plugin
mv server/hooks/web_push/output/* output/plugin
mv server/hooks/wechat_push/output/* output/plugin
mv server/hooks/telegram_push/output/* output/plugins
mv server/hooks/web_push/output/* output/plugins
mv server/hooks/wechat_push/output/* output/plugins
cp README.md output/

View File

@ -71,19 +71,6 @@ configure.
Check if your mailbox has completed all the security configuration. It is recommended to
use [https://www.mail-tester.com/](https://www.mail-tester.com/) for checking.
## 5、 WeChat Message Push
Open the `config/config.json` file in the run directory, edit a few configuration items at the beginning of `weChatPush`
and restart the service.
## 6、Telegram Message Push
Create bot and get token from [BotFather](https://t.me/BotFather)
Open the `config/config.json` file in the run directory, edit a few configuration items at the beginning of `tg`and restart the service.
## 7、WebHook Push
Open the `config/config.json` file in the running directory, edit the webPushUrl and webPushToken (optional). After receiving an email, the email information will be posted to the hook address, and the token will also be placed in the body for easy verification. After configuring, restart the service.
# Configuration file format description
@ -102,14 +89,6 @@ Open the `config/config.json` file in the running directory, edit the webPushUrl
"httpPort": 80, // http port . default 80
"httpsPort": 443, // https port . default 443
"spamFilterLevel": 0,// Spam filter level, 0: no filter, 1: filtering when `spf` and `dkim` don't pass, 2: filtering when `spf` don't pass
"weChatPushAppId": "", // wechat appid
"weChatPushSecret": "", // weChat Secret
"weChatPushTemplateId": "", // weChat TemplateId
"weChatPushUserId": "", // weChat UserId
"tgChatId": "", // telegram chatid
"tgBotToken": "", // telegram token
"webPushUrl": "", // webhook push URL
"webPushToken": "", // webhook push token
"isInit": true // If false, it will enter the bootstrap process.
}
```
@ -124,6 +103,16 @@ SMTP Server Address : smtp.[Your Domain]
SMTP Port: 25/465(SSL)
# Plugin
[WeChat Push](server/hooks/wechat_push/README.md)
[Telegram Push](server/hooks/wechat_push/README.md)
[Web Push](server/hooks/wechat_push/README.md)
# For Developer
## Project Framework
@ -143,3 +132,4 @@ The code is in `server` folder.
## Plugin Development
Reference this file. `server/hooks/wechat_push/wechat_push.go`

View File

@ -77,18 +77,6 @@ PMail是一个追求极简部署流程、极致资源占用的个人域名邮箱
建议找一下邮箱测试服务(比如[https://www.mail-tester.com/](https://www.mail-tester.com/))进行邮件得分检测,避免自己某些步骤漏配,导致发件进对方垃圾箱。
## 5、微信推送
打开运行目录下的 `config/config.json`文件,编辑 `weChatPush` 开头的几个配置项,重启服务即可。
## 6、Telegram推送
从 [BotFather](https://t.me/BotFather) 创建并获取令牌机器人。 打开运行目录下的 config/config.json 文件,编辑 `tg` 开头的几个配置项,重启服务即可。
## 7、WebHook推送
打开运行目录下的 `config/config.json`文件,编辑 webPushUrl 跟webPushToken (可选)接收到邮件后会往hook地址post发送邮件信息token也会放在body中方便需要的进行校验配置完重启服务即可。
# 配置文件说明
```json
@ -106,14 +94,6 @@ PMail是一个追求极简部署流程、极致资源占用的个人域名邮箱
"spamFilterLevel": 0,// 垃圾邮件过滤级别0不过滤、1 spf dkim 校验均失败时过滤2 spf校验不通过时过滤
"httpPort": 80, // http 端口 . 默认 80
"httpsPort": 443, // https 端口 . 默认 443
"weChatPushAppId": "", // 微信推送appid
"weChatPushSecret": "", // 微信推送秘钥
"weChatPushTemplateId": "", // 微信推送模板id
"weChatPushUserId": "", // 微信推送用户id
"tgChatId": "", // telegram 推送chatid
"tgBotToken": "", // telegram 推送 token
"webPushUrl": "", // webhook 推送地址
"webPushToken": "", // webhook 推送 token
"isInit": true // 为false的时候会进入安装引导流程
}
```
@ -128,6 +108,15 @@ SMTP地址 smtp.[你的域名]
SMTP端口 25/465(SSL)
# 插件
[微信推送](server/hooks/wechat_push/README.md)
[Telegram推送](server/hooks/wechat_push/README.md)
[WebHook推送](server/hooks/wechat_push/README.md)
# 参与开发
## 项目架构

View File

@ -0,0 +1,15 @@
## How To Ues
Create bot and get token from [BotFather](https://t.me/BotFather)
Copy plugin binary file to `/plugins`
add config.json to `/plugins/config.com` like this:
```json
{
"tgChatId": "", // telegram chatid
"tgBotToken": "", // telegram token
}
```

View File

@ -0,0 +1,14 @@
## How To Ues
Copy plugin binary file to `/plugins`
add config.json to `/plugins/config.com` like this:
```json
{
"webPushUrl": "", // webhook push URL
"webPushToken": "", // webhook push token
}
```

View File

@ -0,0 +1,15 @@
## How To Ues
Copy plugin binary file to `/plugins`
add config.json to `/plugins/config.com` like this:
```json
{
"weChatPushAppId": "", // wechat appid
"weChatPushSecret": "", // weChat Secret
"weChatPushTemplateId": "", // weChat TemplateId
"weChatPushUserId": "", // weChat UserId
}
```

View File

@ -174,6 +174,7 @@ func NewWechatPushHook() *WeChatPushHook {
}
// 插件将以独立进程运行,因此需要主函数。
func main() {
framework.CreatePlugin(NewWechatPushHook()).Run()
}

View File

@ -1,11 +1,11 @@
package http_server
import (
"flag"
"fmt"
log "github.com/sirupsen/logrus"
"io/fs"
"net/http"
"pmail/config"
"pmail/controllers"
"time"
)
@ -27,9 +27,8 @@ func SetupStart() {
mux.HandleFunc("/.well-known/", controllers.AcmeChallenge)
HttpPort := 80
if config.Instance != nil && config.Instance.HttpPort > 0 {
HttpPort = config.Instance.HttpPort
}
flag.IntVar(&HttpPort, "p", 80, "初始化阶段Http服务端口")
flag.Parse()
log.Infof("HttpServer Start On Port :%d", HttpPort)
setupServer = &http.Server{
Addr: fmt.Sprintf(":%d", HttpPort),

View File

@ -38,6 +38,7 @@ var (
gitHash string
buildTime string
goVersion string
version string
)
func main() {
@ -74,7 +75,7 @@ func main() {
}
log.Infoln("***************************************************")
log.Infof("***\tServer Start Success Version:%s\n", config.Version)
log.Infof("***\tServer Start Success Version:%s\n", version)
log.Infof("***\tGit Commit Hash: %s ", gitHash)
log.Infof("***\tBuild TimeStamp: %s ", buildTime)
log.Infof("***\tBuild GoLang Version: %s ", goVersion)