feat: support different SMTP ports for email sending

- Add conditional logic to handle SMTP_PORT 465 for secure
  connections.
- Use standard SMTP for other ports to allow flexibility in
  email server configurations.

This change enhances the email sending functionality by allowing
users to specify different SMTP ports, improving compatibility
with various email service providers. The previous implementation
only supported port 465, which limited its usability.
This commit is contained in:
songtianlun 2025-01-03 17:14:17 +08:00
parent 5821fefcae
commit f7770955a9

10
mail.sh
View File

@ -20,6 +20,7 @@ Date: $(date -R)
$BODY" $BODY"
if [ "$SMTP_PORT" == 465 ]; then
curl -s --url "smtps://$SMTP_SERVER:$SMTP_PORT" \ curl -s --url "smtps://$SMTP_SERVER:$SMTP_PORT" \
--mail-from "$MAIL_FROM" \ --mail-from "$MAIL_FROM" \
--mail-rcpt "$MAIL_TO" \ --mail-rcpt "$MAIL_TO" \
@ -27,6 +28,15 @@ $BODY"
--ssl-reqd \ --ssl-reqd \
--user "$SMTP_USER:$SMTP_PASS" \ --user "$SMTP_USER:$SMTP_PASS" \
<<< "$email_content" <<< "$email_content"
else
curl -s --url "smtp://$SMTP_SERVER:$SMTP_PORT" \
--mail-from "$MAIL_FROM" \
--mail-rcpt "$MAIL_TO" \
--upload-file - \
--ssl-reqd \
--user "$SMTP_USER:$SMTP_PASS" \
<<< "$email_content"
fi
} }
# 主函数 # 主函数