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:// 下不生效的 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' "$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