refactor: replace sendmail with curl for Gmail notifications
This commit is contained in:
32
notify.sh
32
notify.sh
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user