diff --git a/back/data/notify.ts b/back/data/notify.ts index b0899500..e9cc15d3 100644 --- a/back/data/notify.ts +++ b/back/data/notify.ts @@ -116,6 +116,9 @@ export class EmailNotification extends NotificationBaseInfo { public emailUser: string = ''; public emailPass: string = ''; public emailTo: string = ''; + public emailHost: string = ''; + public emailPort: string = ''; + public emailSecure: string = ''; } export class PushMeNotification extends NotificationBaseInfo { diff --git a/back/services/notify.ts b/back/services/notify.ts index 22609748..33f3962e 100644 --- a/back/services/notify.ts +++ b/back/services/notify.ts @@ -590,16 +590,44 @@ export default class NotificationService { } private async email() { - const { emailPass, emailService, emailUser, emailTo } = this.params; + const { + emailPass, + emailService, + emailUser, + emailTo, + emailHost, + emailPort, + emailSecure, + } = this.params; try { - const transporter = nodemailer.createTransport({ - service: emailService, + const transportConfig: { + service?: string; + host?: string; + port?: number; + secure?: boolean; + auth: { user: string; pass: string }; + } = { auth: { user: emailUser, pass: emailPass, }, - }); + }; + + if (emailHost) { + transportConfig.host = emailHost; + transportConfig.port = emailPort + ? Math.max(1, Math.min(65535, parseInt(emailPort, 10) || 465)) + : 465; + transportConfig.secure = + emailSecure !== undefined && emailSecure !== '' + ? emailSecure === 'true' + : transportConfig.port === 465; + } else { + transportConfig.service = emailService; + } + + const transporter = nodemailer.createTransport(transportConfig); const info = await transporter.sendMail({ from: `"青龙快讯" <${emailUser}>`, diff --git a/src/locales/en-US.json b/src/locales/en-US.json index 0a1a2a2a..2d096070 100644 --- a/src/locales/en-US.json +++ b/src/locales/en-US.json @@ -390,7 +390,11 @@ "调用版本;专业版填写pro,个人版填写personal,为空默认使用专业版": "Version, you can specify 'pro' for the Professional version and 'personal' for the Personal version. If left blank, it will default to the Professional version.", "飞书群组机器人:https://www.feishu.cn/hc/zh-CN/articles/360024984973": "Feishu group bot: https://www.feishu.cn/hc/zh-CN/articles/360024984973", "飞书群组机器人加签密钥,安全设置中开启签名校验后获得": "Feishu group bot signature secret, obtained after enabling signature verification in security settings", + "邮箱服务名称,比如126、163、Gmail、QQ等,支持列表https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json,设置emailHost后此项可不填": "Email service name, e.g., 126, 163, Gmail, QQ, etc. Supported list: https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json. Can be left blank if emailHost is set", "邮箱服务名称,比如126、163、Gmail、QQ等,支持列表https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json": "Email service name, e.g., 126, 163, Gmail, QQ, etc. Supported list: https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json", + "自定义SMTP服务器地址,设置后将忽略emailService中的服务器配置,如smtp.qiye.aliyun.com": "Custom SMTP server address. When set, the server configuration in emailService will be ignored. E.g., smtp.qiye.aliyun.com", + "自定义SMTP端口号,默认465": "Custom SMTP port number, default is 465", + "是否使用SSL/TLS,端口为465时默认为true,否则默认为false": "Whether to use SSL/TLS. Defaults to true when port is 465, otherwise false", "邮箱地址": "Email Address", "SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定": "The SMTP login password may also be a special passphrase, depending on the specific email service provider's instructions", "PushMe的Key,https://push.i-i.me/": "PushMe key, https://push.i-i.me/", diff --git a/src/locales/zh-CN.json b/src/locales/zh-CN.json index 448e140c..d4bdfd1d 100644 --- a/src/locales/zh-CN.json +++ b/src/locales/zh-CN.json @@ -390,7 +390,11 @@ "调用版本;专业版填写pro,个人版填写personal,为空默认使用专业版": "调用版本;专业版填写pro,个人版填写personal,为空默认使用专业版", "飞书群组机器人:https://www.feishu.cn/hc/zh-CN/articles/360024984973": "飞书群组机器人:https://www.feishu.cn/hc/zh-CN/articles/360024984973", "飞书群组机器人加签密钥,安全设置中开启签名校验后获得": "飞书群组机器人加签密钥,安全设置中开启签名校验后获得", + "邮箱服务名称,比如126、163、Gmail、QQ等,支持列表https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json,设置emailHost后此项可不填": "邮箱服务名称,比如126、163、Gmail、QQ等,支持列表https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json,设置emailHost后此项可不填", "邮箱服务名称,比如126、163、Gmail、QQ等,支持列表https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json": "邮箱服务名称,比如126、163、Gmail、QQ等,支持列表https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json", + "自定义SMTP服务器地址,设置后将忽略emailService中的服务器配置,如smtp.qiye.aliyun.com": "自定义SMTP服务器地址,设置后将忽略emailService中的服务器配置,如smtp.qiye.aliyun.com", + "自定义SMTP端口号,默认465": "自定义SMTP端口号,默认465", + "是否使用SSL/TLS,端口为465时默认为true,否则默认为false": "是否使用SSL/TLS,端口为465时默认为true,否则默认为false", "邮箱地址": "邮箱地址", "SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定": "SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定", "PushMe的Key,https://push.i-i.me/": "PushMe的Key,https://push.i-i.me/", diff --git a/src/utils/config.ts b/src/utils/config.ts index b529a7d0..2ab2aa6a 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -406,9 +406,26 @@ export default { { label: 'emailService', tip: intl.get( - '邮箱服务名称,比如126、163、Gmail、QQ等,支持列表https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json', + '邮箱服务名称,比如126、163、Gmail、QQ等,支持列表https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json,设置emailHost后此项可不填', ), - required: true, + }, + { + label: 'emailHost', + tip: intl.get( + '自定义SMTP服务器地址,设置后将忽略emailService中的服务器配置,如smtp.qiye.aliyun.com', + ), + }, + { + label: 'emailPort', + tip: intl.get('自定义SMTP端口号,默认465'), + }, + { + label: 'emailSecure', + tip: intl.get('是否使用SSL/TLS,端口为465时默认为true,否则默认为false'), + items: [ + { value: 'true', label: 'true' }, + { value: 'false', label: 'false' }, + ], }, { label: 'emailUser', tip: intl.get('邮箱认证地址'), required: true }, {