fix(email): report a missing sender address from the SMTP connection test

TestConnection skipped the empty-from guard that Send enforces, so with
no sender and no username configured the test issued the null reverse-path
and could report success against a lenient relay while every real
notification send kept failing with the missing-sender error. Guard the
test path the same way and surface a dedicated translated message.
This commit is contained in:
MHSanaei
2026-07-14 23:00:24 +02:00
parent 97dd724424
commit 9ffbeb4938
15 changed files with 41 additions and 0 deletions
+3
View File
@@ -117,6 +117,9 @@ func (s *EmailService) TestConnection() SMTPTestResult {
if from == "" {
from = username
}
if from == "" {
return SMTPTestResult{false, "send", "smtpFromNotConfigured"}
}
from, fromName = resolveFrom(from, fromName)
recipients := parseRecipients(toStr)
+25
View File
@@ -180,6 +180,31 @@ func TestSendUsesBareAddressFromNameAddrSmtpFrom(t *testing.T) {
}
}
func TestConnectionReportsMissingFrom(t *testing.T) {
if err := database.InitDB(filepath.Join(t.TempDir(), "x-ui.db")); err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = database.CloseDB() })
settingService := service.SettingService{}
mustSet := func(name string, err error) {
t.Helper()
if err != nil {
t.Fatalf("set %s: %v", name, err)
}
}
mustSet("host", settingService.SetSmtpHost("127.0.0.1"))
mustSet("port", settingService.SetSmtpPort(1))
mustSet("to", settingService.SetSmtpTo("admin@example.com"))
mustSet("encryption", settingService.SetSmtpEncryptionType("none"))
got := NewEmailService(settingService).TestConnection()
want := SMTPTestResult{Success: false, Stage: "send", Message: "smtpFromNotConfigured"}
if got != want {
t.Errorf("TestConnection() = %+v, want %+v", got, want)
}
}
func TestBuildMessageStripsHeaderInjection(t *testing.T) {
raw := buildMessage(
"panel@example.com\r\nBcc: evil@example.com",
+1
View File
@@ -1410,6 +1410,7 @@
"smtpTestSuccess": "تم إرسال البريد التجريبي بنجاح",
"smtpHostNotConfigured": "خادم SMTP غير مهيأ",
"smtpNoRecipients": "لا يوجد مستلمون مهيؤون",
"smtpFromNotConfigured": "عنوان مرسل SMTP غير مُهيأ",
"eventLoginAttempt": "محاولة تسجيل دخول",
"telegramTokenConfigured": "مهيأ؛ اتركه فارغاً للاحتفاظ بالتوكن الحالي.",
"telegramTokenPlaceholder": "مهيأ — أدخل توكن جديد لاستبداله",
+1
View File
@@ -1529,6 +1529,7 @@
"smtpTestSuccess": "Test email sent successfully",
"smtpHostNotConfigured": "SMTP host not configured",
"smtpNoRecipients": "No recipients configured",
"smtpFromNotConfigured": "SMTP sender address not configured",
"eventLoginAttempt": "Login attempt",
"telegramTokenConfigured": "Configured; leave blank to keep current token.",
"telegramTokenPlaceholder": "Configured - enter a new token to replace",
+1
View File
@@ -1410,6 +1410,7 @@
"smtpTestSuccess": "Correo de prueba enviado correctamente",
"smtpHostNotConfigured": "Servidor SMTP no configurado",
"smtpNoRecipients": "No hay destinatarios configurados",
"smtpFromNotConfigured": "La dirección del remitente SMTP no está configurada",
"eventLoginAttempt": "Intento de inicio de sesión",
"telegramTokenConfigured": "Configurado; deje en blanco para mantener el token actual.",
"telegramTokenPlaceholder": "Configurado: introduzca un nuevo token para reemplazarlo",
+1
View File
@@ -1412,6 +1412,7 @@
"smtpTestSuccess": "ایمیل آزمایشی با موفقیت ارسال شد",
"smtpHostNotConfigured": "میزبان SMTP پیکربندی نشده است",
"smtpNoRecipients": "هیچ گیرنده‌ای پیکربندی نشده است",
"smtpFromNotConfigured": "آدرس فرستنده SMTP پیکربندی نشده است",
"eventLoginAttempt": "تلاش برای ورود",
"telegramTokenConfigured": "پیکربندی شده؛ برای حفظ توکن فعلی خالی بگذارید.",
"telegramTokenPlaceholder": "پیکربندی شده - برای جایگزینی، توکن جدید وارد کنید",
+1
View File
@@ -1410,6 +1410,7 @@
"smtpTestSuccess": "Email uji berhasil dikirim",
"smtpHostNotConfigured": "Host SMTP belum dikonfigurasi",
"smtpNoRecipients": "Tidak ada penerima yang dikonfigurasi",
"smtpFromNotConfigured": "Alamat pengirim SMTP belum dikonfigurasi",
"eventLoginAttempt": "Percobaan masuk",
"telegramTokenConfigured": "Terkonfigurasi; kosongkan untuk mempertahankan token saat ini.",
"telegramTokenPlaceholder": "Terkonfigurasi - masukkan token baru untuk mengganti",
+1
View File
@@ -1410,6 +1410,7 @@
"smtpTestSuccess": "テストメールを正常に送信しました",
"smtpHostNotConfigured": "SMTPホストが設定されていません",
"smtpNoRecipients": "受信者が設定されていません",
"smtpFromNotConfigured": "SMTP送信者アドレスが設定されていません",
"eventLoginAttempt": "ログイン試行",
"telegramTokenConfigured": "設定済み。現在のトークンを維持する場合は空欄のままにしてください。",
"telegramTokenPlaceholder": "設定済み - 置き換えるには新しいトークンを入力してください",
+1
View File
@@ -1410,6 +1410,7 @@
"smtpTestSuccess": "E-mail de teste enviado com sucesso",
"smtpHostNotConfigured": "Servidor SMTP não configurado",
"smtpNoRecipients": "Nenhum destinatário configurado",
"smtpFromNotConfigured": "Endereço do remetente SMTP não configurado",
"eventLoginAttempt": "Tentativa de login",
"telegramTokenConfigured": "Configurado; deixe em branco para manter o token atual.",
"telegramTokenPlaceholder": "Configurado - insira um novo token para substituir",
+1
View File
@@ -1410,6 +1410,7 @@
"smtpTestSuccess": "Тестовое письмо отправлено успешно",
"smtpHostNotConfigured": "SMTP хост не настроен",
"smtpNoRecipients": "Получатели не настроены",
"smtpFromNotConfigured": "Адрес отправителя SMTP не настроен",
"eventLoginAttempt": "Попытка входа",
"telegramTokenConfigured": "Настроен; оставьте пустым для сохранения текущего токена.",
"telegramTokenPlaceholder": "Настроен - введите новый токен для замены",
+1
View File
@@ -1410,6 +1410,7 @@
"smtpTestSuccess": "Test e-postası başarıyla gönderildi",
"smtpHostNotConfigured": "SMTP sunucusu yapılandırılmamış",
"smtpNoRecipients": "Yapılandırılmış alıcı yok",
"smtpFromNotConfigured": "SMTP gönderen adresi yapılandırılmamış",
"eventLoginAttempt": "Oturum açma denemesi",
"telegramTokenConfigured": "Yapılandırıldı; mevcut belirteci korumak için boş bırakın.",
"telegramTokenPlaceholder": "Yapılandırıldı - değiştirmek için yeni bir belirteç girin",
+1
View File
@@ -1410,6 +1410,7 @@
"smtpTestSuccess": "Тестовий лист успішно надіслано",
"smtpHostNotConfigured": "Хост SMTP не налаштовано",
"smtpNoRecipients": "Отримувачів не налаштовано",
"smtpFromNotConfigured": "Адресу відправника SMTP не налаштовано",
"eventLoginAttempt": "Спроба входу",
"telegramTokenConfigured": "Налаштовано; залиште порожнім, щоб зберегти поточний токен.",
"telegramTokenPlaceholder": "Налаштовано — введіть новий токен для заміни",
+1
View File
@@ -1410,6 +1410,7 @@
"smtpTestSuccess": "Đã gửi email thử nghiệm thành công",
"smtpHostNotConfigured": "Chưa cấu hình máy chủ SMTP",
"smtpNoRecipients": "Chưa cấu hình người nhận",
"smtpFromNotConfigured": "Chưa cấu hình địa chỉ người gửi SMTP",
"eventLoginAttempt": "Lần thử đăng nhập",
"telegramTokenConfigured": "Đã cấu hình; để trống để giữ token hiện tại.",
"telegramTokenPlaceholder": "Đã cấu hình - nhập token mới để thay thế",
+1
View File
@@ -1410,6 +1410,7 @@
"smtpTestSuccess": "测试邮件发送成功",
"smtpHostNotConfigured": "尚未配置 SMTP 主机",
"smtpNoRecipients": "尚未配置收件人",
"smtpFromNotConfigured": "未配置 SMTP 发件人地址",
"eventLoginAttempt": "登录尝试",
"telegramTokenConfigured": "已配置;留空则保留当前令牌。",
"telegramTokenPlaceholder": "已配置——输入新令牌以替换",
+1
View File
@@ -1410,6 +1410,7 @@
"smtpTestSuccess": "測試郵件已成功傳送",
"smtpHostNotConfigured": "尚未設定 SMTP 主機",
"smtpNoRecipients": "尚未設定收件人",
"smtpFromNotConfigured": "未設定 SMTP 寄件人地址",
"eventLoginAttempt": "登入嘗試",
"telegramTokenConfigured": "已設定;留空以保留目前的權杖。",
"telegramTokenPlaceholder": "已設定 - 輸入新權杖以取代",