fix(notify-email): 修 smtps:// 下 -H + --upload-file - 不生效的 bug
lint / yamllint (push) Successful in 5m27s

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 完整到达。
This commit is contained in:
beforegolive
2026-07-15 13:32:42 +08:00
parent 25e21fd0c7
commit 3f9fa1f9c9
+9 -5
View File
@@ -53,16 +53,20 @@ runs:
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' "$BODY" | curl -fsS --ssl \
if ! printf '%s' "$EMAIL" | 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)"