fix gmail send error

This commit is contained in:
2025-12-30 11:06:36 +07:00
parent 6472fe639a
commit 002788fc03

View File

@@ -37,29 +37,43 @@ send_ntfy() {
fi fi
} }
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
# Function: Send to Gmail # Function: Send to Gmail
send_gmail() { send_gmail() {
if [ -n "$GMAIL_USER" ] && [ -n "$GMAIL_TO" ] && [ -n "$GMAIL_PASS" ]; then if [ -n "$GMAIL_USER" ] && [ -n "$GMAIL_TO" ] && [ -n "$GMAIL_PASS" ]; then
echo "[Gmail] Sending..." echo -e "${YELLOW}======================================${NC}"
echo -e "${YELLOW}Gmail SMTP Email${NC}"
echo -e "${YELLOW}======================================${NC}"
echo ""
echo -e "From: ${GREEN}$GMAIL_USER${NC}"
echo -e "To: ${GREEN}$GMAIL_TO${NC}"
echo -e "SMTP: ${GREEN}smtp.gmail.com:587${NC}"
echo ""
# Send via curl (portable, no sendmail needed) SUBJECT="$ICON $TITLE"
if curl -s --url "smtps://smtp.gmail.com:465" --ssl-reqd \ BODY="$MESSAGE"
--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 email_content="To: $GMAIL_TO\nSubject: $SUBJECT\n\n$MESSAGE"
EOF response=$(echo "$email_content" | curl --ssl-reqd \
then --url "smtp://smtp.gmail.com:587" \
--user "$GMAIL_USER:$GMAIL_PASS" \
--mail-from "$GMAIL_USER" \
--mail-rcpt "$GMAIL_TO" \
--upload-file - \
--silent \
--show-error 2>&1)
exit_code=$?
if [ $exit_code -eq 0 ]; then
echo "[Gmail] Sent." echo "[Gmail] Sent."
else else
echo "[Gmail] Failed." echo "[Gmail] Failed."
fi fi
fi
} }
# Function: Send to Telegram # Function: Send to Telegram