refactor: replace sendmail with curl for Gmail notifications

This commit is contained in:
2025-12-29 16:57:11 +07:00
parent 19ba568834
commit 6472fe639a

View File

@@ -40,21 +40,25 @@ send_ntfy() {
# Function: Send to Gmail
send_gmail() {
if [ -n "$GMAIL_USER" ] && [ -n "$GMAIL_TO" ] && [ -n "$GMAIL_PASS" ]; then
if ! command -v sendmail &> /dev/null; then
echo "[Gmail] Warning: sendmail not found, skipping."
return
fi
echo "[Gmail] Sending..."
{
echo "Subject: $ICON $TITLE"
echo "From: $GMAIL_USER"
echo "To: $GMAIL_TO"
echo ""
echo "$MESSAGE"
} | sendmail -S smtp.gmail.com:587 \
-au"$GMAIL_USER" \
-ap"$GMAIL_PASS" \
"$GMAIL_TO" && echo "[Gmail] Sent." || echo "[Gmail] Failed."
# Send via curl (portable, no sendmail needed)
if curl -s --url "smtps://smtp.gmail.com:465" --ssl-reqd \
--user "$GMAIL_USER:$GMAIL_PASS" \
--mail-from "$GMAIL_USER" \
--mail-rcpt "$GMAIL_TO" \
--upload-file - <<EOF
From: $GMAIL_USER
To: $GMAIL_TO
Subject: $ICON $TITLE
$MESSAGE
EOF
then
echo "[Gmail] Sent."
else
echo "[Gmail] Failed."
fi
fi
}