feat: add email notification and logging features

- Introduce email notification configuration options in the README
- Create a new config.sh file for managing environment variables
- Implement mail.sh for sending email notifications
- Add logging functionality to main.sh for tracking synchronization processes

These changes enhance the functionality of the script by allowing users to receive email notifications about the synchronization status and maintain logs of the operations performed. The new configuration options provide flexibility in managing email settings and improve the overall usability of the tool.
This commit is contained in:
songtianlun
2025-01-03 17:03:01 +08:00
parent bf753e1255
commit 534a9ab0e4
5 changed files with 222 additions and 224 deletions

43
mail.sh Normal file
View File

@@ -0,0 +1,43 @@
#!/bin/bash
# 参数获取
SMTP_SERVER="$1"
SMTP_PORT="$2"
SMTP_USER="$3"
SMTP_PASS="$4"
MAIL_TO="$5"
MAIL_FROM="$6"
SUBJECT="$7"
BODY="$8"
# 发送邮件
send_mail() {
local email_content="Subject: $SUBJECT
From: $MAIL_FROM
To: $MAIL_TO
Content-Type: text/plain; charset=UTF-8
Date: $(date -R)
$BODY"
curl -s --url "smtps://$SMTP_SERVER:$SMTP_PORT" \
--mail-from "$MAIL_FROM" \
--mail-rcpt "$MAIL_TO" \
--upload-file - \
--ssl-reqd \
--user "$SMTP_USER:$SMTP_PASS" \
<<< "$email_content"
}
# 主函数
main() {
# 验证必要参数
if [ -z "$SMTP_SERVER" ] || [ -z "$SMTP_USER" ] || [ -z "$SMTP_PASS" ] || [ -z "$MAIL_TO" ]; then
echo "错误: 缺少必要的邮件配置"
exit 1
fi
send_mail
}
main "$@"