mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-22 20:46:38 +08:00
282b788258
fix #6046 smtp relay may allow empty password, although this is usually not safe
34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
import { FactoryProvider, Logger } from '@nestjs/common';
|
|
import { createTransport, Transporter } from 'nodemailer';
|
|
import SMTPTransport from 'nodemailer/lib/smtp-transport';
|
|
|
|
import { Config } from '../config';
|
|
|
|
export const MAILER_SERVICE = Symbol('MAILER_SERVICE');
|
|
|
|
export type MailerService = Transporter<SMTPTransport.SentMessageInfo>;
|
|
export type Response = SMTPTransport.SentMessageInfo;
|
|
export type Options = SMTPTransport.Options;
|
|
|
|
export const MAILER: FactoryProvider<
|
|
Transporter<SMTPTransport.SentMessageInfo> | undefined
|
|
> = {
|
|
provide: MAILER_SERVICE,
|
|
useFactory: (config: Config) => {
|
|
if (config.mailer) {
|
|
const logger = new Logger('Mailer');
|
|
const auth = config.mailer.auth;
|
|
if (auth && auth.user && !('pass' in auth)) {
|
|
logger.warn(
|
|
'Mailer service has not configured password, please make sure your mailer service allow empty password.'
|
|
);
|
|
}
|
|
|
|
return createTransport(config.mailer);
|
|
} else {
|
|
return undefined;
|
|
}
|
|
},
|
|
inject: [Config],
|
|
};
|