[PR #5941] [MERGED] fix(email): build an RFC 5322 message with a proper From address #6033

Closed
opened 2026-11-02 04:05:53 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5941
Author: @yukh975
Created: 7/13/2026
Status: ✅ Merged
Merged: 7/14/2026
Merged by: @MHSanaei

Base: main ← Head: fix/smtp-from-header


📝 Commits (1)

  • d878716 fix(email): build an RFC 5322 message with a proper From address and name

📊 Changes

25 files changed (+293 additions, -15 deletions)

View changed files

📝 frontend/public/openapi.json (+16 -0)
📝 frontend/src/generated/examples.ts (+4 -0)
📝 frontend/src/generated/schemas.ts (+16 -0)
📝 frontend/src/generated/types.ts (+4 -0)
📝 frontend/src/generated/zod.ts (+4 -0)
📝 frontend/src/models/setting.ts (+2 -0)
📝 frontend/src/pages/settings/EmailTab.tsx (+10 -0)
➕ internal/web/entity/check_valid_test.go (+29 -0)
📝 internal/web/entity/entity.go (+9 -0)
📝 internal/web/service/email/email.go (+48 -15)
➕ internal/web/service/email/email_test.go (+81 -0)
📝 internal/web/service/setting.go (+18 -0)
📝 internal/web/translation/ar-EG.json (+4 -0)
📝 internal/web/translation/en-US.json (+4 -0)
📝 internal/web/translation/es-ES.json (+4 -0)
📝 internal/web/translation/fa-IR.json (+4 -0)
📝 internal/web/translation/id-ID.json (+4 -0)
📝 internal/web/translation/ja-JP.json (+4 -0)
📝 internal/web/translation/pt-BR.json (+4 -0)
📝 internal/web/translation/ru-RU.json (+4 -0)

...and 5 more files

📄 Description

Problem

Sending a notification or test email from the panel can be rejected by strict receivers. With Gmail the server returns:

550-5.7.1 ... Messages missing a valid address in From: header, or having no From: header, are not accepted.

Root cause

buildMessage set the From: header to the raw SMTP username and emitted only From/To/Subject/MIME-Version/Content-Type:

  1. When the SMTP login is not a bare email address (common with relays / submission services), From: carries no valid address and the message is rejected.
  2. There is no Date: (mandatory per RFC 5322 §3.6) and no Message-ID:, both of which also raise the spam score (e.g. SpamAssassin MISSING_DATE / MISSING_MID).

Fix

  • Add two settings: smtpFrom (sender address) and smtpFromName (optional display name). From falls back to the username when smtpFrom is empty, so existing setups are unchanged.
  • Reassemble the message with net/mail: a proper name-addr From ("Name" <addr>), a Date, a Message-ID, and an RFC 2047 encoded Subject, in a deterministic header order.

Resulting message:

Date: Mon, 13 Jul 2026 15:47:21 +0300
From: "3x-ui" <panel@example.com>
To: admin@example.com
Message-ID: <c99cb6a1...@example.com>
Subject: =?utf-8?q?...?=
MIME-Version: 1.0
Content-Type: text/html; charset=utf-8

Changes

  • Backend: smtpFrom / smtpFromName settings (model, defaults, getters), SMTP send + test paths, buildMessage rewrite.
  • Frontend: two fields in the Email settings tab; regenerated Zod/OpenAPI artifacts (make gen).
  • i18n: new keys in all 13 locale files.
  • Tests: buildMessage unit tests (message parsed back with net/mail).

Compatibility

Backward compatible — with smtpFrom empty the From address is still the username, as before (now correctly formatted as a name-addr).


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/5941 **Author:** [@yukh975](https://github.com/yukh975) **Created:** 7/13/2026 **Status:** ✅ Merged **Merged:** 7/14/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/smtp-from-header` --- ### 📝 Commits (1) - [`d878716`](https://github.com/MHSanaei/3x-ui/commit/d87871640ef1bb4a9200f43283794aaebefd2a8d) fix(email): build an RFC 5322 message with a proper From address and name ### 📊 Changes **25 files changed** (+293 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `frontend/public/openapi.json` (+16 -0) 📝 `frontend/src/generated/examples.ts` (+4 -0) 📝 `frontend/src/generated/schemas.ts` (+16 -0) 📝 `frontend/src/generated/types.ts` (+4 -0) 📝 `frontend/src/generated/zod.ts` (+4 -0) 📝 `frontend/src/models/setting.ts` (+2 -0) 📝 `frontend/src/pages/settings/EmailTab.tsx` (+10 -0) ➕ `internal/web/entity/check_valid_test.go` (+29 -0) 📝 `internal/web/entity/entity.go` (+9 -0) 📝 `internal/web/service/email/email.go` (+48 -15) ➕ `internal/web/service/email/email_test.go` (+81 -0) 📝 `internal/web/service/setting.go` (+18 -0) 📝 `internal/web/translation/ar-EG.json` (+4 -0) 📝 `internal/web/translation/en-US.json` (+4 -0) 📝 `internal/web/translation/es-ES.json` (+4 -0) 📝 `internal/web/translation/fa-IR.json` (+4 -0) 📝 `internal/web/translation/id-ID.json` (+4 -0) 📝 `internal/web/translation/ja-JP.json` (+4 -0) 📝 `internal/web/translation/pt-BR.json` (+4 -0) 📝 `internal/web/translation/ru-RU.json` (+4 -0) _...and 5 more files_ </details> ### 📄 Description ### Problem Sending a notification or test email from the panel can be rejected by strict receivers. With Gmail the server returns: > 550-5.7.1 ... Messages missing a valid address in From: header, or having no From: header, are not accepted. ### Root cause `buildMessage` set the `From:` header to the raw SMTP **username** and emitted only `From`/`To`/`Subject`/`MIME-Version`/`Content-Type`: 1. When the SMTP login is not a bare email address (common with relays / submission services), `From:` carries no valid address and the message is rejected. 2. There is **no `Date:`** (mandatory per RFC 5322 §3.6) and **no `Message-ID:`**, both of which also raise the spam score (e.g. SpamAssassin `MISSING_DATE` / `MISSING_MID`). ### Fix - Add two settings: **`smtpFrom`** (sender address) and **`smtpFromName`** (optional display name). `From` falls back to the username when `smtpFrom` is empty, so existing setups are unchanged. - Reassemble the message with `net/mail`: a proper name-addr `From` (`"Name" <addr>`), a `Date`, a `Message-ID`, and an RFC 2047 encoded `Subject`, in a deterministic header order. Resulting message: ``` Date: Mon, 13 Jul 2026 15:47:21 +0300 From: "3x-ui" <panel@example.com> To: admin@example.com Message-ID: <c99cb6a1...@example.com> Subject: =?utf-8?q?...?= MIME-Version: 1.0 Content-Type: text/html; charset=utf-8 ``` ### Changes - **Backend:** `smtpFrom` / `smtpFromName` settings (model, defaults, getters), SMTP send + test paths, `buildMessage` rewrite. - **Frontend:** two fields in the Email settings tab; regenerated Zod/OpenAPI artifacts (`make gen`). - **i18n:** new keys in all 13 locale files. - **Tests:** `buildMessage` unit tests (message parsed back with `net/mail`). ### Compatibility Backward compatible — with `smtpFrom` empty the `From` address is still the username, as before (now correctly formatted as a `name-addr`). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:05:53 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6033
No description provided.