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
}
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
# Function: Send to Gmail
send_gmail() {
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)
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
SUBJECT="$ICON $TITLE"
BODY="$MESSAGE"
$MESSAGE
EOF
then
email_content="To: $GMAIL_TO\nSubject: $SUBJECT\n\n$MESSAGE"
response=$(echo "$email_content" | curl --ssl-reqd \
--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."
else
echo "[Gmail] Failed."
fi
fi
}
# Function: Send to Telegram