Files
ci-actions/notify-email/action.yml
T
beforegolive 3f9fa1f9c9
lint / yamllint (push) Successful in 5m27s
fix(notify-email): 修 smtps:// 下 -H + --upload-file - 不生效的 bug
curl 在 smtps:// 模式下,'-H' 头部和 '--upload-file -' body 同时给时,
实际 DATA 段几乎为空(实测 97 bytes 上行 vs 完整邮件 289 bytes),
收件人看不到 Subject 和 body。

改为:把整封邮件(From/To/Subject/MIME-Version/Content-Type/Date + 空行 +
body)拼好后从 stdin 给 curl --upload-file -,不再用 -H。

实测:上行 289 bytes,subject / body 完整到达。
2026-07-15 13:32:42 +08:00

73 lines
2.5 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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
# 整封邮件拼好(headers + 空行 + body)从 stdin 给 curl --upload-file -
# 避开 "-H + --upload-file -" 组合在 smtps:// 下不生效的 bugcurl 不会把 -H
# 头部合并进 DATA 段,结果只发空 body)。v1.0.0 是这么写的,1.0.1 改成全量 stdin。
# 同时给出一个明确的 Date 头部,避免 163 反垃圾系统把无 Date 的邮件归类。
DATE_HDR=$(date -R)
EMAIL=$(printf 'From: %s\nTo: %s\nSubject: %s\nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nDate: %s\n\n%s' \
"$FROM_ADDR" "$TO_ADDR" "$SUBJECT" "$DATE_HDR" "$BODY")
# shellcheck disable=SC2086
if ! printf '%s' "$EMAIL" | curl -fsS --ssl \
--url "smtps://${SMTP_HOST}:${SMTP_PORT}" \
--user "${SMTP_USER}:${SMTP_PASS}" \
--mail-from "${FROM_ADDR}" \
$RCPT_ARGS \
--max-time 15 --retry 2 \
--upload-file -; then
echo "::warning::Email send failed (non-fatal)"
fi