diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3b30c15..6d3589b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -33,21 +33,32 @@ jobs: EMAIL_PASS: ${{ secrets.EMAIL_PASS }} TO_EMAIL: 1627832236@qq.com run: | - # 1. 构建邮件内容 + # 2. 修复邮件头格式:加编码、明确From为邮箱格式、Subject转义 email_content=$(cat < # QQ要求From必须是“名称<邮箱>”格式 + To: ${TO_EMAIL} + Subject: =?UTF-8?B?${base64_subject}?= # 解决中文主题乱码+协议错误 + Content-Type: text/plain; charset=UTF-8 # 明确编码,避免特殊字符问题 + Content-Transfer-Encoding: 8bit + + 通知:有新的内容已推送到仓库「toutoukan」的main分支! + 仓库地址:https://github.com/mayimingperson/toutoukan # 替换为实际仓库地址 + 触发时间:$(date +"%Y-%m-%d %H:%M:%S") # 增加动态时间,便于排查 EOF ) - # 2. 用curl发送邮件 - curl -v "smtps://$SMTP_SERVER:$SMTP_PORT" - --mail-from "$EMAIL_USER" - --mail-rcpt "$TO_EMAIL" - --user "$EMAIL_USER:$EMAIL_PASS" - -T <(echo "$email_content") + # 3. 中文主题转Base64(QQ邮箱要求,否则可能触发协议错误) + base64_subject=$(echo -n "推送仓库成功" | base64) + + # 4. 修复curl命令:明确smtps协议、加超时重试、输出详细日志 + 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 处理换行符,确保格式正确