Skip to content

feat: 支持强制使用 AUTH LOGIN 以解决 outlook 等邮箱的发件问题 - #4112

Merged
Calcium-Ion merged 6 commits into
QuantumNous:mainfrom
Hoshino-Yumetsuki:main
Apr 8, 2026
Merged

feat: 支持强制使用 AUTH LOGIN 以解决 outlook 等邮箱的发件问题#4112
Calcium-Ion merged 6 commits into
QuantumNous:mainfrom
Hoshino-Yumetsuki:main

Conversation

@Hoshino-Yumetsuki

@Hoshino-Yumetsuki Hoshino-Yumetsuki commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Added a new SMTP setting to force AUTH LOGIN authentication, exposed as a checkbox in SMTP configuration.
  • Internationalization

    • The new SMTP setting label is localized in English, French, Japanese, Russian, Vietnamese, Simplified Chinese, and Traditional Chinese.

@coderabbitai

coderabbitai Bot commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 823165de-25b9-48a4-a88f-1d9ef75aedc9

📥 Commits

Reviewing files that changed from the base of the PR and between e03c4f2 and 4e7f9c3.

📒 Files selected for processing (8)
  • common/email.go
  • web/src/i18n/locales/en.json
  • web/src/i18n/locales/fr.json
  • web/src/i18n/locales/ja.json
  • web/src/i18n/locales/ru.json
  • web/src/i18n/locales/vi.json
  • web/src/i18n/locales/zh-CN.json
  • web/src/i18n/locales/zh-TW.json

Walkthrough

Adds a boolean SMTP option SMTPForceAuthLogin and uses it in new helper logic to choose AUTH LOGIN vs PLAIN SMTP authentication; persists the option in backend option handling; exposes a checkbox in the frontend settings; and adds i18n entries for the new label across locales.

Changes

Cohort / File(s) Summary
SMTP config & mail-sending logic
common/constants.go, common/email.go, model/option.go
Add exported SMTPForceAuthLogin bool; introduce shouldUseSMTPLoginAuth() and getSMTPAuth() to select/produce SMTP auth (LOGIN vs PLAIN) and refactor SendEmail to use the computed auth; wire option parsing to update the new flag.
Frontend settings
web/src/components/settings/SystemSetting.jsx
Add SMTPForceAuthLogin into form state, normalize loaded value as boolean, and add a checkbox wired to existing immediate-persist handler.
Internationalization
web/src/i18n/locales/en.json, web/src/i18n/locales/fr.json, web/src/i18n/locales/ja.json, web/src/i18n/locales/ru.json, web/src/i18n/locales/vi.json, web/src/i18n/locales/zh-CN.json, web/src/i18n/locales/zh-TW.json
Add translation key/value for the label "强制使用 AUTH LOGIN" in seven locales.

Sequence Diagram

sequenceDiagram
    participant UI as Settings UI
    participant Config as Backend Config
    participant Logic as getSMTPAuth()
    participant Auth as AuthMechanism
    participant SMTP as SMTP Server

    UI->>Config: Toggle/Save SMTPForceAuthLogin
    Config->>Logic: Provide SMTPForceAuthLogin, SMTPAccount, SMTPServer, SMTPToken
    Logic->>Logic: shouldUseSMTPLoginAuth()? (force flag, isOutlookServer, server list)
    alt Use AUTH LOGIN
        Logic->>Auth: Create LoginAuth(account, token)
    else Use PLAIN
        Logic->>Auth: Create PlainAuth(account, token, server)
    end
    Logic->>SMTP: Send email using computed Auth
    SMTP-->>Logic: Response / auth result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A little toggle hops into the mail,
Forcing AUTH LOGIN down every trail,
Seven tongues chime in to say,
Click the box — and send away! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding support for forcing AUTH LOGIN to resolve Outlook email sending issues.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@common/email.go`:
- Around line 90-92: The SSL (SSL/465) send path currently leaves auth as
smtp.PlainAuth so SMTPForceAuthLogin is ignored; update the SSL branch where
auth is set (the branch that currently uses smtp.PlainAuth for SSL) to respect
the same logic as the non-SSL branch by calling shouldUseSMTPLoginAuth() (or
checking SMTPForceAuthLogin) and assigning auth = LoginAuth(SMTPAccount,
SMTPToken) when appropriate before calling smtp.SendMail; ensure the SSL path
uses the same auth variable (and passes it to smtp.SendMail) so forced AUTH
LOGIN behavior applies to both SSL and non-SSL flows.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b8aed63f-1d3f-448f-9818-4e06765b283c

📥 Commits

Reviewing files that changed from the base of the PR and between 677d02f and 62aa987.

⛔ Files ignored due to path filters (1)
  • web/bun.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • common/constants.go
  • common/email.go
  • common/email_auth_selection_test.go
  • model/option.go
  • model/option_smtp_auth_test.go
  • web/src/components/settings/SystemSetting.jsx

Comment thread common/email.go Outdated
@Calcium-Ion

Copy link
Copy Markdown
Member

感谢您的pr,我们发现email_auth_selection_test.go这个测试文件并不需要提交上来,您可以去掉测试文件后重新提交吗

@Hoshino-Yumetsuki

Copy link
Copy Markdown
Contributor Author

感谢您的pr,我们发现email_auth_selection_test.go这个测试文件并不需要提交上来,您可以去掉测试文件后重新提交吗

已经移除

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
common/email.go (1)

22-24: ⚠️ Potential issue | 🔴 Critical

SMTPForceAuthLogin is used at Line 23 but appears undeclared (compile blocker).

shouldUseSMTPLoginAuth() references SMTPForceAuthLogin, but in the provided common/constants.go SMTP globals (Lines 80-85), this symbol is missing. This will fail with undefined: SMTPForceAuthLogin.

🔧 Minimal fix
--- a/common/constants.go
+++ b/common/constants.go
@@
 var SMTPToken = ""
+var SMTPForceAuthLogin = false
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@common/email.go` around lines 22 - 24, The function shouldUseSMTPLoginAuth
references an undeclared symbol SMTPForceAuthLogin; add a package-level
declaration for SMTPForceAuthLogin (e.g., var SMTPForceAuthLogin bool = false)
to the SMTP globals in common/constants.go, or if an existing flag like
SMTPForceAuth was intended, replace SMTPForceAuthLogin with that symbol in
shouldUseSMTPLoginAuth; ensure the chosen symbol is exported/defined in the same
package so the code compiles.
🧹 Nitpick comments (1)
common/email.go (1)

97-100: Remove redundant conditional at Line 97.

else if shouldUseSMTPLoginAuth() and else execute the exact same smtp.SendMail(...) call, so this branch is dead logic after introducing getSMTPAuth().

♻️ Simplification
-	} else if shouldUseSMTPLoginAuth() {
-		err = smtp.SendMail(addr, auth, SMTPFrom, to, mail)
-	} else {
+	} else {
 		err = smtp.SendMail(addr, auth, SMTPFrom, to, mail)
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@common/email.go` around lines 97 - 100, The conditional branch checking
shouldUseSMTPLoginAuth() is redundant because both branches call
smtp.SendMail(addr, auth, SMTPFrom, to, mail); remove the else-if/else branching
and replace it with a single smtp.SendMail(...) invocation (assigning to err)
after obtaining auth via getSMTPAuth() so the logic in the function that calls
smtp.SendMail is simplified and uses the same variables (addr, auth, SMTPFrom,
to, mail).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@common/email.go`:
- Around line 22-27: The SMTPForceAuthLogin flag is used by
shouldUseSMTPLoginAuth but isn't persisted/loaded from options; add
SMTPForceAuthLogin to the option mapping in model/option.go so admin/UI changes
persist and load correctly — update the options map/struct entry for
SMTPForceAuthLogin with its default value and proper key, and ensure it is
included in the load/save/encode paths the file uses (the same pattern used for
other SMTP_* keys) so shouldUseSMTPLoginAuth reads the persisted setting.

---

Duplicate comments:
In `@common/email.go`:
- Around line 22-24: The function shouldUseSMTPLoginAuth references an
undeclared symbol SMTPForceAuthLogin; add a package-level declaration for
SMTPForceAuthLogin (e.g., var SMTPForceAuthLogin bool = false) to the SMTP
globals in common/constants.go, or if an existing flag like SMTPForceAuth was
intended, replace SMTPForceAuthLogin with that symbol in shouldUseSMTPLoginAuth;
ensure the chosen symbol is exported/defined in the same package so the code
compiles.

---

Nitpick comments:
In `@common/email.go`:
- Around line 97-100: The conditional branch checking shouldUseSMTPLoginAuth()
is redundant because both branches call smtp.SendMail(addr, auth, SMTPFrom, to,
mail); remove the else-if/else branching and replace it with a single
smtp.SendMail(...) invocation (assigning to err) after obtaining auth via
getSMTPAuth() so the logic in the function that calls smtp.SendMail is
simplified and uses the same variables (addr, auth, SMTPFrom, to, mail).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: aedf1c76-ae1c-4492-982b-e6e8cd4eba4c

📥 Commits

Reviewing files that changed from the base of the PR and between e96a950 and 5ee4c10.

⛔ Files ignored due to path filters (1)
  • web/bun.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • common/constants.go
  • common/email.go
  • model/option.go
  • model/option_smtp_auth_test.go
  • web/src/components/settings/SystemSetting.jsx
✅ Files skipped from review due to trivial changes (1)
  • model/option_smtp_auth_test.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • web/src/components/settings/SystemSetting.jsx
  • common/constants.go
  • model/option.go

Comment thread common/email.go
Hoshino-Yumetsuki and others added 2 commits April 8, 2026 15:51
- Remove redundant else-if branch in SendEmail since auth is already
  computed via getSMTPAuth()
- Delete option_smtp_auth_test.go as requested
- Add i18n translations for '强制使用 AUTH LOGIN' checkbox
@Calcium-Ion
Calcium-Ion merged commit a18ea3c into QuantumNous:main Apr 8, 2026
1 check was pending
nonepage referenced this pull request in nonepage/new-api Apr 13, 2026
* feat: 支持强制使用 AUTH LOGIN 以解决 outlook 等邮箱的发件问题

* fix: 修复通过 SSL 发送邮件时绕过 AUTH LOGIN 的问题

* fix: remove redundant branch, delete test file, add i18n translations

- Remove redundant else-if branch in SendEmail since auth is already
  computed via getSMTPAuth()
- Delete option_smtp_auth_test.go as requested
- Add i18n translations for '强制使用 AUTH LOGIN' checkbox

(cherry picked from commit a18ea3cc167ec69be05052fc8f35b74d974a4856)
TonyTown6033 pushed a commit to TonyTown6033/new-api that referenced this pull request Apr 17, 2026
* feat: 支持强制使用 AUTH LOGIN 以解决 outlook 等邮箱的发件问题

* fix: 修复通过 SSL 发送邮件时绕过 AUTH LOGIN 的问题

* fix: remove redundant branch, delete test file, add i18n translations

- Remove redundant else-if branch in SendEmail since auth is already
  computed via getSMTPAuth()
- Delete option_smtp_auth_test.go as requested
- Add i18n translations for '强制使用 AUTH LOGIN' checkbox

(cherry picked from commit a18ea3c)
xyfacai pushed a commit to xyfacai/new-api that referenced this pull request Apr 20, 2026
* feat: 支持强制使用 AUTH LOGIN 以解决 outlook 等邮箱的发件问题

* fix: 修复通过 SSL 发送邮件时绕过 AUTH LOGIN 的问题

* fix: remove redundant branch, delete test file, add i18n translations

- Remove redundant else-if branch in SendEmail since auth is already
  computed via getSMTPAuth()
- Delete option_smtp_auth_test.go as requested
- Add i18n translations for '强制使用 AUTH LOGIN' checkbox
rockyicer pushed a commit to rockyicer/new-api that referenced this pull request May 7, 2026
* feat: 支持强制使用 AUTH LOGIN 以解决 outlook 等邮箱的发件问题

* fix: 修复通过 SSL 发送邮件时绕过 AUTH LOGIN 的问题

* fix: remove redundant branch, delete test file, add i18n translations

- Remove redundant else-if branch in SendEmail since auth is already
  computed via getSMTPAuth()
- Delete option_smtp_auth_test.go as requested
- Add i18n translations for '强制使用 AUTH LOGIN' checkbox
Jinxuans referenced this pull request in TokFlux-Org/TokFlux May 9, 2026
* feat: 支持强制使用 AUTH LOGIN 以解决 outlook 等邮箱的发件问题

* fix: 修复通过 SSL 发送邮件时绕过 AUTH LOGIN 的问题

* fix: remove redundant branch, delete test file, add i18n translations

- Remove redundant else-if branch in SendEmail since auth is already
  computed via getSMTPAuth()
- Delete option_smtp_auth_test.go as requested
- Add i18n translations for '强制使用 AUTH LOGIN' checkbox
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants