feat(notify-email): composite action 通过 SMTP 发邮件 + lint workflow
lint / yamllint (push) Successful in 12s

- notify-email 用 curl smtps:// 协议,163/126 兼容
- self-mail 模式:USER/TO 可同账号
- 失败时 ::warning:: 不阻塞
- lint workflow: yamllint 验证 action.yml 语法
This commit is contained in:
gitea_admin
2026-07-13 09:36:06 +08:00
parent 2e99202570
commit 25e21fd0c7
3 changed files with 129 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
# notify-email
通过 SMTP 发送 Gitea Actions run 结果邮件。**已验证兼容 163 / 126 邮箱**。
## Inputs
| 名称 | 必填 | 默认 | 说明 |
|---|---|---|---|
| `smtp_host` | ✅ | — | 例:`smtp.163.com` |
| `smtp_port` | ❌ | `465` | SSL 端口 |
| `smtp_user` | ✅ | — | 完整邮箱地址 |
| `smtp_pass` | ✅ | — | 授权码(业务 repo 配 Gitea secret |
| `from` | ❌ | = `smtp_user` | 发件人 |
| `to` | ✅ | — | 收件人,多个用逗号 |
| `subject` | ✅ | — | 邮件主题 |
| `body` | ✅ | — | 邮件正文(纯文本) |
## 使用示例
```yaml
- uses: gitea_admin/ci-actions/notify-email@v1
with:
smtp_host: smtp.163.com
smtp_user: ${{ secrets.EMAIL_USER }}
smtp_pass: ${{ secrets.EMAIL_SMTP_PASS }}
to: ${{ secrets.EMAIL_TO }}
subject: "[gitea-ci] ${{ github.repository }} - ${{ needs.build.result }}"
body: |
repository: ${{ github.repository }}
workflow: ${{ github.workflow }}
status: ${{ needs.build.result }}
url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
```
## 安全
`smtp_pass` **必须**通过 Gitea secret 传入,**不要**直接写在 workflow 里。
## 失败处理
邮件发送失败时输出 `::warning::Email send failed (non-fatal)`**不阻塞**调用方 job。
+69
View File
@@ -0,0 +1,69 @@
name: 'Notify Email'
description: 'Send Gitea Actions run result via SMTP (163/126 compatible)'
author: 'gitea_admin'
inputs:
smtp_host:
description: 'SMTP host (e.g. smtp.126.com)'
required: true
smtp_port:
description: 'SMTP SSL port'
required: false
default: '465'
smtp_user:
description: 'SMTP user (full email address)'
required: true
smtp_pass:
description: 'SMTP authorization code'
required: true
from:
description: 'From address'
required: false
default: ${{ inputs.smtp_user }}
to:
description: 'Recipient(s), comma separated'
required: true
subject:
description: 'Email subject'
required: true
body:
description: 'Email body (plain text)'
required: true
runs:
using: 'composite'
steps:
- name: Send email via SMTP
shell: bash
env:
SMTP_HOST: ${{ inputs.smtp_host }}
SMTP_PORT: ${{ inputs.smtp_port }}
SMTP_USER: ${{ inputs.smtp_user }}
SMTP_PASS: ${{ inputs.smtp_pass }}
FROM_ADDR: ${{ inputs.from }}
TO_ADDR: ${{ inputs.to }}
SUBJECT: ${{ inputs.subject }}
BODY: ${{ inputs.body }}
run: |
set -u
# 构造 --mail-rcpt 参数(每个收件人一个)
RCPT_ARGS=""
IFS=','
for addr in $TO_ADDR; do
RCPT_ARGS="$RCPT_ARGS --mail-rcpt $(printf '%s' "$addr" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
done
unset IFS
# shellcheck disable=SC2086
if ! printf '%s' "$BODY" | curl -fsS --ssl \
--url "smtps://${SMTP_HOST}:${SMTP_PORT}" \
--user "${SMTP_USER}:${SMTP_PASS}" \
--mail-from "${FROM_ADDR}" \
$RCPT_ARGS \
-H "Subject: ${SUBJECT}" \
-H "From: ${FROM_ADDR}" \
-H "To: ${TO_ADDR}" \
-H "Content-Type: text/plain; charset=UTF-8" \
--max-time 15 --retry 2 \
--upload-file -; then
echo "::warning::Email send failed (non-fatal)"
fi