@ -12,6 +12,7 @@ type CommentEmailConfig = {
} ;
} ;
const logger = log4js . getLogger ( "COMMENT_EMAIL_TEST" ) ;
const logger = log4js . getLogger ( "COMMENT_EMAIL_TEST" ) ;
const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/ ;
export class CommentEmailTestValidationError extends Error {
export class CommentEmailTestValidationError extends Error {
constructor ( message : string ) {
constructor ( message : string ) {
@ -40,6 +41,9 @@ export function assertAdminEmailReady(adminEmail: string | null | undefined): as
if ( ! adminEmail || adminEmail . trim ( ) . length === 0 ) {
if ( ! adminEmail || adminEmail . trim ( ) . length === 0 ) {
throw new CommentEmailTestValidationError ( "当前管理员账号未配置邮箱,无法接收测试邮件" ) ;
throw new CommentEmailTestValidationError ( "当前管理员账号未配置邮箱,无法接收测试邮件" ) ;
}
}
if ( ! EMAIL_REGEX . test ( adminEmail . trim ( ) ) ) {
throw new CommentEmailTestValidationError ( "当前管理员账号邮箱格式不合法" ) ;
}
}
}
export async function sendCommentEmailTestMail ( input : {
export async function sendCommentEmailTestMail ( input : {
@ -54,6 +58,9 @@ export async function sendCommentEmailTestMail(input: {
host : input.config.smtpHost ,
host : input.config.smtpHost ,
port : input.config.smtpPort ,
port : input.config.smtpPort ,
secure : input.config.smtpSecure ,
secure : input.config.smtpSecure ,
connectionTimeout : 10_000 ,
greetingTimeout : 10_000 ,
socketTimeout : 15_000 ,
auth : {
auth : {
user : input.config.smtpUser ,
user : input.config.smtpUser ,
pass : input.config.smtpPass ,
pass : input.config.smtpPass ,