From f7770955a9f121a9c227a03b508ee019d927095b Mon Sep 17 00:00:00 2001 From: songtianlun Date: Fri, 3 Jan 2025 17:14:17 +0800 Subject: [PATCH] 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. --- mail.sh | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/mail.sh b/mail.sh index ad00fda..e8e7e6d 100644 --- a/mail.sh +++ b/mail.sh @@ -20,13 +20,23 @@ Date: $(date -R) $BODY" - curl -s --url "smtps://$SMTP_SERVER:$SMTP_PORT" \ - --mail-from "$MAIL_FROM" \ - --mail-rcpt "$MAIL_TO" \ - --upload-file - \ - --ssl-reqd \ - --user "$SMTP_USER:$SMTP_PASS" \ - <<< "$email_content" + if [ "$SMTP_PORT" == 465 ]; then + curl -s --url "smtps://$SMTP_SERVER:$SMTP_PORT" \ + --mail-from "$MAIL_FROM" \ + --mail-rcpt "$MAIL_TO" \ + --upload-file - \ + --ssl-reqd \ + --user "$SMTP_USER:$SMTP_PASS" \ + <<< "$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 } # 主函数