From c893b5452e02aa5cc8c7b0f87fe9a408101cc1e1 Mon Sep 17 00:00:00 2001 From: Marvin Zhang Date: Mon, 22 Jul 2024 17:34:55 +0800 Subject: [PATCH] refactor: Update SMTPPort type to int in NotificationChannelV2 model --- core/models/models/v2/notification_channel_v2.go | 2 +- core/notification/mail.go | 9 +-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/core/models/models/v2/notification_channel_v2.go b/core/models/models/v2/notification_channel_v2.go index 0b86a6b8..61698de5 100644 --- a/core/models/models/v2/notification_channel_v2.go +++ b/core/models/models/v2/notification_channel_v2.go @@ -8,7 +8,7 @@ type NotificationChannelV2 struct { Description string `json:"description" bson:"description"` Provider string `json:"provider" bson:"provider"` SMTPServer string `json:"smtp_server" bson:"smtp_server"` - SMTPPort string `json:"smtp_port" bson:"smtp_port"` + SMTPPort int `json:"smtp_port" bson:"smtp_port"` SMTPUsername string `json:"smtp_username" bson:"smtp_username"` SMTPPassword string `json:"smtp_password" bson:"smtp_password"` WebhookUrl string `json:"webhook_url" bson:"webhook_url"` diff --git a/core/notification/mail.go b/core/notification/mail.go index b35764f1..5a6eeb19 100644 --- a/core/notification/mail.go +++ b/core/notification/mail.go @@ -10,21 +10,14 @@ import ( "net/mail" "regexp" "runtime/debug" - "strconv" "strings" ) func SendMail(s *models.NotificationSettingV2, ch *models.NotificationChannelV2, to, cc, bcc, title, content string) error { // config - port, err := strconv.Atoi(ch.SMTPPort) - if err != nil { - log.Errorf("failed to convert SMTP port to int: %v", err) - trace.PrintError(err) - return err - } smtpConfig := smtpAuthentication{ Server: ch.SMTPServer, - Port: port, + Port: ch.SMTPPort, SenderIdentity: s.SenderName, SenderEmail: s.SenderEmail, SMTPUser: ch.SMTPUsername,