feat: add config for mail server name (#13632)

fix #13627

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Added configurable display names for primary and fallback SMTP
servers, improving email sender identification.
* Defaults to “AFFiNE Server,” with support for MAILER_SERVERNAME
environment variable for the primary SMTP.
* Exposed in admin settings for easy setup alongside existing SMTP
options.
* Names are now passed through to mail transport options for consistent
use across emails.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
DarkSky
2025-09-22 19:52:15 +08:00
committed by GitHub
parent 7fe95f50f4
commit e3f3c8c4a8
4 changed files with 31 additions and 0 deletions

View File

@@ -195,6 +195,11 @@
"type": "object", "type": "object",
"description": "Configuration for mailer module", "description": "Configuration for mailer module",
"properties": { "properties": {
"SMTP.name": {
"type": "string",
"description": "Name of the email server (e.g. your domain name)\n@default \"AFFiNE Server\"\n@environment `MAILER_SERVERNAME`",
"default": "AFFiNE Server"
},
"SMTP.host": { "SMTP.host": {
"type": "string", "type": "string",
"description": "Host of the email server (e.g. smtp.gmail.com)\n@default \"\"\n@environment `MAILER_HOST`", "description": "Host of the email server (e.g. smtp.gmail.com)\n@default \"\"\n@environment `MAILER_HOST`",
@@ -230,6 +235,11 @@
"description": "The emails from these domains are always sent using the fallback SMTP server.\n@default []", "description": "The emails from these domains are always sent using the fallback SMTP server.\n@default []",
"default": [] "default": []
}, },
"fallbackSMTP.name": {
"type": "string",
"description": "Name of the fallback email server (e.g. your domain name)\n@default \"AFFiNE Server\"",
"default": "AFFiNE Server"
},
"fallbackSMTP.host": { "fallbackSMTP.host": {
"type": "string", "type": "string",
"description": "Host of the email server (e.g. smtp.gmail.com)\n@default \"\"", "description": "Host of the email server (e.g. smtp.gmail.com)\n@default \"\"",

View File

@@ -6,6 +6,7 @@ declare global {
interface AppConfigSchema { interface AppConfigSchema {
mailer: { mailer: {
SMTP: { SMTP: {
name: string;
host: string; host: string;
port: number; port: number;
username: string; username: string;
@@ -16,6 +17,7 @@ declare global {
fallbackDomains: ConfigItem<string[]>; fallbackDomains: ConfigItem<string[]>;
fallbackSMTP: { fallbackSMTP: {
name: string;
host: string; host: string;
port: number; port: number;
username: string; username: string;
@@ -28,6 +30,11 @@ declare global {
} }
defineModuleConfig('mailer', { defineModuleConfig('mailer', {
'SMTP.name': {
desc: 'Name of the email server (e.g. your domain name)',
default: 'AFFiNE Server',
env: 'MAILER_SERVERNAME',
},
'SMTP.host': { 'SMTP.host': {
desc: 'Host of the email server (e.g. smtp.gmail.com)', desc: 'Host of the email server (e.g. smtp.gmail.com)',
default: '', default: '',
@@ -64,6 +71,10 @@ defineModuleConfig('mailer', {
default: [], default: [],
shape: z.array(z.string()), shape: z.array(z.string()),
}, },
'fallbackSMTP.name': {
desc: 'Name of the fallback email server (e.g. your domain name)',
default: 'AFFiNE Server',
},
'fallbackSMTP.host': { 'fallbackSMTP.host': {
desc: 'Host of the email server (e.g. smtp.gmail.com)', desc: 'Host of the email server (e.g. smtp.gmail.com)',
default: '', default: '',

View File

@@ -20,6 +20,7 @@ function configToSMTPOptions(
config: AppConfig['mailer']['SMTP'] config: AppConfig['mailer']['SMTP']
): SMTPTransport.Options { ): SMTPTransport.Options {
return { return {
name: config.name,
host: config.host, host: config.host,
port: config.port, port: config.port,
tls: { tls: {

View File

@@ -89,6 +89,11 @@
} }
}, },
"mailer": { "mailer": {
"SMTP.name": {
"type": "String",
"desc": "Name of the email server (e.g. your domain name)",
"env": "MAILER_SERVERNAME"
},
"SMTP.host": { "SMTP.host": {
"type": "String", "type": "String",
"desc": "Host of the email server (e.g. smtp.gmail.com)", "desc": "Host of the email server (e.g. smtp.gmail.com)",
@@ -123,6 +128,10 @@
"type": "Array", "type": "Array",
"desc": "The emails from these domains are always sent using the fallback SMTP server." "desc": "The emails from these domains are always sent using the fallback SMTP server."
}, },
"fallbackSMTP.name": {
"type": "String",
"desc": "Name of the fallback email server (e.g. your domain name)"
},
"fallbackSMTP.host": { "fallbackSMTP.host": {
"type": "String", "type": "String",
"desc": "Host of the email server (e.g. smtp.gmail.com)" "desc": "Host of the email server (e.g. smtp.gmail.com)"