Update main.yml
This commit is contained in:
60
.github/workflows/main.yml
vendored
60
.github/workflows/main.yml
vendored
@@ -22,50 +22,18 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: 检出代码仓库
|
- name: 检出代码仓库
|
||||||
uses: actions/checkout@v4 # 必须添加,否则无法使用git命令
|
uses: actions/checkout@v4
|
||||||
- name: install email tool
|
|
||||||
run: |
|
|
||||||
sudo apt update -y
|
|
||||||
sudo apt install -y sendmail
|
|
||||||
- name: send email
|
|
||||||
env:
|
|
||||||
SMTP_SERVER: ${{ secrets.SMTP_SERVER }}
|
|
||||||
SMTP_PORT: ${{ secrets.SMTP_PORT }}
|
|
||||||
EMAIL_USER: ${{ secrets.EMAIL_USER }}
|
|
||||||
EMAIL_PASS: ${{ secrets.EMAIL_PASS }}
|
|
||||||
TO_EMAIL: 1627832236@qq.com
|
|
||||||
run: |
|
|
||||||
if [ -z "$SMTP_SERVER" ] || [ -z "$SMTP_PORT" ]; then
|
|
||||||
echo "错误:SMTP_SERVER或SMTP_PORT未设置"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 1. 修复URL格式(强制处理)
|
- name: 发送邮件
|
||||||
smtp_url="smtps://${SMTP_SERVER}:${SMTP_PORT}"
|
uses: dawidd6/action-send-mail@v3
|
||||||
smtp_url=$(echo "$smtp_url" | tr -d '[:space:]' | sed 's/[^a-zA-Z0-9_.:\/-]//g') # 移除所有非法字符
|
with:
|
||||||
echo "最终SMTP URL: [$smtp_url]" # 必须显示为[smtps://smtp.qq.com:465]
|
server_address: smtp.qq.com
|
||||||
|
server_port: 465
|
||||||
# 2. 中文主题编码
|
username: ${{ secrets.EMAIL_USER }}
|
||||||
base64_subject=$(echo -n "推送仓库成功" | base64 | tr -d '\n')
|
password: ${{ secrets.EMAIL_PASS }}
|
||||||
|
subject: "推送仓库成功"
|
||||||
# 3. 构建邮件内容(现在git命令可用)
|
body: "通知:有新的内容已推送到仓库「toutoukan」的main分支!!\n推送时间: $(date +'%Y-%m-%d %H:%M:%S')\n推送作者: $(git log -1 --pretty=format:'%an')\n提交信息: $(git log -1 --pretty=format:'%s')"
|
||||||
email_content=$(cat <<-EOF
|
to: 1627832236@qq.com
|
||||||
From: ${EMAIL_USER}
|
from: ${{ secrets.EMAIL_USER }}
|
||||||
To: ${TO_EMAIL}
|
# 如果使用 SSL
|
||||||
Subject: =?UTF-8?B?${base64_subject}?=
|
secure: true
|
||||||
|
|
||||||
通知:有新的内容已推送到仓库「toutoukan」的main分支!!
|
|
||||||
推送时间: $(date +"%Y-%m-%d %H:%M:%S")
|
|
||||||
推送作者: $(git log -1 --pretty=format:'%an')
|
|
||||||
提交信息: $(git log -1 --pretty=format:'%s')
|
|
||||||
EOF
|
|
||||||
)
|
|
||||||
|
|
||||||
# 4. 发送邮件(与本地成功命令一致)
|
|
||||||
curl -v \
|
|
||||||
--tlsv1.2 \
|
|
||||||
--mail-from "$EMAIL_USER" \
|
|
||||||
--mail-rcpt "$TO_EMAIL" \
|
|
||||||
--user "$EMAIL_USER:$EMAIL_PASS" \
|
|
||||||
-T <(echo -e "$email_content") \
|
|
||||||
"$smtp_url"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user