Update main.yml
This commit is contained in:
51
.github/workflows/main.yml
vendored
51
.github/workflows/main.yml
vendored
@@ -33,32 +33,39 @@ jobs:
|
||||
EMAIL_PASS: ${{ secrets.EMAIL_PASS }}
|
||||
TO_EMAIL: 1627832236@qq.com
|
||||
run: |
|
||||
# 2. 修复邮件头格式:加编码、明确From为邮箱格式、Subject转义
|
||||
email_content=$(cat <<EOF
|
||||
From: "${EMAIL_USER}" <${EMAIL_USER}> # QQ要求From必须是“名称<邮箱>”格式
|
||||
To: ${TO_EMAIL}
|
||||
Subject: =?UTF-8?B?${base64_subject}?= # 解决中文主题乱码+协议错误
|
||||
Content-Type: text/plain; charset=UTF-8 # 明确编码,避免特殊字符问题
|
||||
Content-Transfer-Encoding: 8bit
|
||||
# 验证SMTP参数是否正确(调试用,可删除)
|
||||
echo "SMTP服务器: $SMTP_SERVER"
|
||||
echo "SMTP端口: $SMTP_PORT"
|
||||
echo "发件人: $EMAIL_USER"
|
||||
|
||||
通知:有新的内容已推送到仓库「toutoukan」的main分支!!
|
||||
仓库地址:https://github.com/mayimingperson/toutoukan # 替换为实际仓库地址
|
||||
触发时间:$(date +"%Y-%m-%d %H:%M:%S") # 增加动态时间,便于排查
|
||||
# 检查URL格式是否正确(调试用,可删除)
|
||||
smtp_url="smtps://$SMTP_SERVER:$SMTP_PORT"
|
||||
echo "SMTP URL: $smtp_url"
|
||||
|
||||
# 中文主题Base64编码
|
||||
base64_subject=$(echo -n "推送仓库成功" | base64)
|
||||
|
||||
# 构建邮件内容
|
||||
email_content=$(cat <<EOF
|
||||
From: "$EMAIL_USER" <$EMAIL_USER>
|
||||
To: $TO_EMAIL
|
||||
Subject: =?UTF-8?B?$base64_subject?=
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
|
||||
通知:有新的内容已推送到仓库「toutoukan」的main分支
|
||||
推送时间: $(date +"%Y-%m-%d %H:%M:%S")
|
||||
EOF
|
||||
)
|
||||
|
||||
# 3. 中文主题转Base64(QQ邮箱要求,否则可能触发协议错误)
|
||||
base64_subject=$(echo -n "推送仓库成功" | base64)
|
||||
|
||||
# 4. 修复curl命令:明确smtps协议、加超时重试、输出详细日志
|
||||
# 发送邮件(修复URL格式)
|
||||
curl -v \
|
||||
--connect-timeout 10 \ # 超时时间,避免卡壳
|
||||
--max-time 20 \ # 最大执行时间
|
||||
--smtp-ssl \ # 强制启用SSL(适配QQ邮箱)
|
||||
--mail-from "${EMAIL_USER}" \
|
||||
--mail-rcpt "${TO_EMAIL}" \
|
||||
--user "${EMAIL_USER}:${EMAIL_PASS}" \
|
||||
"smtps://${SMTP_SERVER}:${SMTP_PORT}" \
|
||||
-T <(echo -e "${email_content}") # -e 处理换行符,确保格式正确
|
||||
--connect-timeout 10 \
|
||||
--max-time 20 \
|
||||
--smtp-ssl \
|
||||
--mail-from "$EMAIL_USER" \
|
||||
--mail-rcpt "$TO_EMAIL" \
|
||||
--user "$EMAIL_USER:$EMAIL_PASS" \
|
||||
"$smtp_url" \ # 使用预定义的URL变量,避免格式错误
|
||||
-T <(echo -e "$email_content")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user