From f71a8a16035352a7c71c86b9024d4f9241374190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=98=AD?= <81747598+lan-yonghui@users.noreply.github.com> Date: Tue, 14 Oct 2025 18:04:41 +0800 Subject: [PATCH] feat: Support configuration of SMTP username (#10636) --- agent/app/dto/alert.go | 2 ++ agent/app/service/alert.go | 6 +++++- agent/utils/alert/alert.go | 6 +++++- frontend/src/api/interface/alert.ts | 1 + frontend/src/lang/modules/en.ts | 1 + frontend/src/lang/modules/es-es.ts | 1 + frontend/src/lang/modules/ja.ts | 1 + frontend/src/lang/modules/ko.ts | 1 + frontend/src/lang/modules/ms.ts | 1 + frontend/src/lang/modules/pt-br.ts | 1 + frontend/src/lang/modules/ru.ts | 1 + frontend/src/lang/modules/tr.ts | 1 + frontend/src/lang/modules/zh-Hant.ts | 1 + frontend/src/lang/modules/zh.ts | 1 + frontend/src/views/setting/alert/setting/email/index.vue | 9 +++++++++ frontend/src/views/setting/alert/setting/index.vue | 5 +++++ 16 files changed, 37 insertions(+), 2 deletions(-) diff --git a/agent/app/dto/alert.go b/agent/app/dto/alert.go index eed2c8974..0c6ba35ed 100644 --- a/agent/app/dto/alert.go +++ b/agent/app/dto/alert.go @@ -292,6 +292,7 @@ type AlertConfigTest struct { Host string `json:"host"` Port int `json:"port"` Sender string `json:"sender"` + UserName string `json:"userName"` Password string `json:"password"` DisplayName string `json:"displayName"` Encryption string `json:"encryption"` // "ssl" / "tls" / "none" @@ -323,6 +324,7 @@ type AlertEmailConfig struct { Host string `json:"host"` Port int `json:"port"` Sender string `json:"sender"` + UserName string `json:"userName"` Password string `json:"password"` DisplayName string `json:"displayName"` Encryption string `json:"encryption"` // "ssl" / "tls" / "none" diff --git a/agent/app/service/alert.go b/agent/app/service/alert.go index c56c2aa50..c0a2c023f 100644 --- a/agent/app/service/alert.go +++ b/agent/app/service/alert.go @@ -479,10 +479,14 @@ func (a AlertService) DeleteAlertConfig(id uint) error { } func (a AlertService) TestAlertConfig(req dto.AlertConfigTest) (bool, error) { + username := req.UserName + if username == "" { + username = req.Sender + } cfg := email.SMTPConfig{ Host: req.Host, Port: req.Port, - Username: req.Sender, + Username: username, Password: req.Password, From: fmt.Sprintf("%s <%s>", req.DisplayName, req.Sender), Encryption: req.Encryption, diff --git a/agent/utils/alert/alert.go b/agent/utils/alert/alert.go index c60b18298..4faf15e94 100644 --- a/agent/utils/alert/alert.go +++ b/agent/utils/alert/alert.go @@ -60,10 +60,14 @@ func CreateEmailAlertLog(create dto.AlertLogCreate, alert dto.AlertDTO, params [ if err != nil { return err } + username := emailInfo.UserName + if username == "" { + username = emailInfo.Sender + } smtpConfig := email.SMTPConfig{ Host: emailInfo.Host, Port: emailInfo.Port, - Username: emailInfo.Sender, + Username: username, Password: emailInfo.Password, From: fmt.Sprintf("%s <%s>", emailInfo.DisplayName, emailInfo.Sender), Encryption: emailInfo.Encryption, diff --git a/frontend/src/api/interface/alert.ts b/frontend/src/api/interface/alert.ts index 7939930d8..ad168f2ba 100644 --- a/frontend/src/api/interface/alert.ts +++ b/frontend/src/api/interface/alert.ts @@ -152,6 +152,7 @@ export namespace Alert { port: number; host: string; sender: string; + userName: string; password: string; displayName: string; encryption: string; diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index aedad5751..08defedc5 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -3899,6 +3899,7 @@ const message = { licenseExceptionRule: 'License exception alert, sent {0} times per day', panelLoginRule: 'Panel login alert, sent {0} times per day', sshLoginRule: 'SSH login alert, sent {0} times per day', + userNameHelper: 'Username is empty, the sender address will be used by default', }, theme: { lingXiaGold: 'Ling Xia Gold', diff --git a/frontend/src/lang/modules/es-es.ts b/frontend/src/lang/modules/es-es.ts index 707a99c26..a04d11a27 100644 --- a/frontend/src/lang/modules/es-es.ts +++ b/frontend/src/lang/modules/es-es.ts @@ -3836,6 +3836,7 @@ const message = { licenseExceptionRule: 'Alerta de licencia anómala, {0} envíos/día', panelLoginRule: 'Alerta de login en panel, {0} envíos/día', sshLoginRule: 'Alerta de login SSH, {0} envíos/día', + userNameHelper: 'El nombre de usuario está vacío, se usará la dirección del remitente por defecto', }, theme: { lingXiaGold: 'Ling Xia Gold', diff --git a/frontend/src/lang/modules/ja.ts b/frontend/src/lang/modules/ja.ts index 115478ffc..4240225ef 100644 --- a/frontend/src/lang/modules/ja.ts +++ b/frontend/src/lang/modules/ja.ts @@ -3779,6 +3779,7 @@ const message = { licenseExceptionRule: 'ライセンス異常アラートは、1日あたり{0}回送信', panelLoginRule: 'パネルログインアラートは、1日あたり{0}回送信', sshLoginRule: 'SSHログインアラートは、1日あたり{0}回送信', + userNameHelper: 'ユーザー名が空の場合、送信者のアドレスがデフォルトで使用されます', }, theme: { lingXiaGold: '凌霞金', diff --git a/frontend/src/lang/modules/ko.ts b/frontend/src/lang/modules/ko.ts index c2e66db9f..bb74701fc 100644 --- a/frontend/src/lang/modules/ko.ts +++ b/frontend/src/lang/modules/ko.ts @@ -3709,6 +3709,7 @@ const message = { licenseExceptionRule: '라이선스 이상 알림은 하루 {0}회 전송', panelLoginRule: '패널 로그인 알림은 하루 {0}회 전송', sshLoginRule: 'SSH 로그인 알림은 하루 {0}회 전송', + userNameHelper: '사용자 이름이 비어 있으면 기본적으로 발신자 주소가 사용됩니다', }, theme: { lingXiaGold: '링샤 골드', diff --git a/frontend/src/lang/modules/ms.ts b/frontend/src/lang/modules/ms.ts index 02baaef3d..77973e328 100644 --- a/frontend/src/lang/modules/ms.ts +++ b/frontend/src/lang/modules/ms.ts @@ -3857,6 +3857,7 @@ const message = { licenseExceptionRule: 'Amaran kerosakan lesen, dihantar {0} kali sehari', panelLoginRule: 'Amaran log masuk panel, dihantar {0} kali sehari', sshLoginRule: 'Amaran log masuk SSH, dihantar {0} kali sehari', + userNameHelper: 'Nama pengguna kosong, alamat penghantar akan digunakan secara lalai', }, theme: { lingXiaGold: 'Ling Xia Emas', diff --git a/frontend/src/lang/modules/pt-br.ts b/frontend/src/lang/modules/pt-br.ts index b5c7a3905..1b3333602 100644 --- a/frontend/src/lang/modules/pt-br.ts +++ b/frontend/src/lang/modules/pt-br.ts @@ -3875,6 +3875,7 @@ const message = { licenseExceptionRule: 'Alerta de exceção de licença, enviado {0} vezes por dia', panelLoginRule: 'Alerta de login no painel, enviado {0} vezes por dia', sshLoginRule: 'Alerta de login SSH, enviado {0} vezes por dia', + userNameHelper: 'O nome de usuário está vazio, o endereço do remetente será usado por padrão', }, theme: { lingXiaGold: 'Ling Xia Gold', diff --git a/frontend/src/lang/modules/ru.ts b/frontend/src/lang/modules/ru.ts index 743680344..31806bab6 100644 --- a/frontend/src/lang/modules/ru.ts +++ b/frontend/src/lang/modules/ru.ts @@ -3870,6 +3870,7 @@ const message = { licenseExceptionRule: 'Оповещение о сбое лицензии, отправляется {0} раз в день', panelLoginRule: 'Оповещение о входе в панель, отправляется {0} раз в день', sshLoginRule: 'Оповещение о входе по SSH, отправляется {0} раз в день', + userNameHelper: 'Имя пользователя не указано, по умолчанию будет использоваться адрес отправителя', }, theme: { lingXiaGold: 'Лин Ся Золотой', diff --git a/frontend/src/lang/modules/tr.ts b/frontend/src/lang/modules/tr.ts index 27aa7967e..6efbf3687 100644 --- a/frontend/src/lang/modules/tr.ts +++ b/frontend/src/lang/modules/tr.ts @@ -3945,6 +3945,7 @@ const message = { licenseExceptionRule: 'Lisans hatası uyarısı, günde {0} kez gönderilir', panelLoginRule: 'Panel girişi uyarısı, günde {0} kez gönderilir', sshLoginRule: 'SSH girişi uyarısı, günde {0} kez gönderilir', + userNameHelper: 'Kullanıcı adı boşsa, varsayılan olarak gönderici adresi kullanılacaktır', }, theme: { lingXiaGold: 'Ling Xia Altın', diff --git a/frontend/src/lang/modules/zh-Hant.ts b/frontend/src/lang/modules/zh-Hant.ts index a0084384c..11c40e818 100644 --- a/frontend/src/lang/modules/zh-Hant.ts +++ b/frontend/src/lang/modules/zh-Hant.ts @@ -3627,6 +3627,7 @@ const message = { licenseExceptionRule: '許可證異常告警,每天發送 {0} 次', panelLoginRule: '面板登入告警,每天發送 {0} 次', sshLoginRule: 'SSH 登入告警,每天發送 {0} 次', + userNameHelper: '使用者名稱為空時,將預設使用寄件者地址', }, theme: { lingXiaGold: '凌霞金', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 6b80b397a..1a46ed1b1 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -3595,6 +3595,7 @@ const message = { licenseExceptionRule: '许可证异常告警,每天发送 {0} 次', panelLoginRule: '面板登录告警,每天发送 {0} 次', sshLoginRule: 'SSH 登录告警告警,每天发送 {0} 次', + userNameHelper: '用户名为空会默认使用发件箱地址', }, theme: { lingXiaGold: '凌霞金', diff --git a/frontend/src/views/setting/alert/setting/email/index.vue b/frontend/src/views/setting/alert/setting/email/index.vue index d01ff8fa0..6aee4a40c 100644 --- a/frontend/src/views/setting/alert/setting/email/index.vue +++ b/frontend/src/views/setting/alert/setting/email/index.vue @@ -22,6 +22,12 @@ {{ $t('xpack.alert.senderHelper') }} + + + + {{ $t('xpack.alert.userNameHelper') }} + + @@ -103,6 +109,7 @@ interface Config { status: string; displayName: string; sender: string; + userName: string; password: string; host: string; port: number; @@ -122,6 +129,7 @@ const form = reactive({ displayName: '', sender: '', password: '', + userName: '', host: '', port: 465, encryption: 'NONE', @@ -170,6 +178,7 @@ const onTest = async (formEl: FormInstance | undefined) => { if (!valid) return; loading.value = true; try { + debugger; await TestAlertConfig(form.config) .then((res) => { loading.value = false; diff --git a/frontend/src/views/setting/alert/setting/index.vue b/frontend/src/views/setting/alert/setting/index.vue index 2a4e97969..f5bbfcec6 100644 --- a/frontend/src/views/setting/alert/setting/index.vue +++ b/frontend/src/views/setting/alert/setting/index.vue @@ -82,6 +82,9 @@ {{ emailConfig.config.sender }} + + {{ emailConfig.config.userName || emailConfig.config.sender }} + {{ emailConfig.config.host }} @@ -186,6 +189,7 @@ export interface EmailConfig { config: { status?: string; sender?: string; + userName?: string; password?: string; displayName?: string; host?: string; @@ -202,6 +206,7 @@ const defaultEmailConfig: EmailConfig = { config: { displayName: '', sender: '', + userName: '', password: '', host: '', port: 25,