From 3f9fa1f9c91ce70650bf70753b374dcea67fc2b1 Mon Sep 17 00:00:00 2001 From: beforegolive Date: Wed, 15 Jul 2026 13:32:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(notify-email):=20=E4=BF=AE=20smtps://=20?= =?UTF-8?q?=E4=B8=8B=20-H=20+=20--upload-file=20-=20=E4=B8=8D=E7=94=9F?= =?UTF-8?q?=E6=95=88=E7=9A=84=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 完整到达。 --- notify-email/action.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/notify-email/action.yml b/notify-email/action.yml index 437a194..087b7e8 100644 --- a/notify-email/action.yml +++ b/notify-email/action.yml @@ -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:// 下不生效的 bug(curl 不会把 -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)"