mirror of
https://github.com/Unleash/unleash.git
synced 2025-07-26 13:48:33 +02:00
Added ability to set additional transport options to email service (#1589)
Co-authored-by: Wilco Schoneveld <wilco.schoneveld@politie.nl>
This commit is contained in:
parent
6ffc492127
commit
c30e92dc49
@ -1,3 +1,4 @@
|
||||
import nodemailer from 'nodemailer';
|
||||
import { EmailService } from './email-service';
|
||||
import noLoggerProvider from '../../test/fixtures/no-logger';
|
||||
|
||||
@ -47,3 +48,35 @@ test('Can send welcome mail', async () => {
|
||||
expect(content.from).toBe('noreply@getunleash.ai');
|
||||
expect(content.subject).toBe('Welcome to Unleash');
|
||||
});
|
||||
|
||||
test('Can supply additional SMTP transport options', async () => {
|
||||
const spy = jest.spyOn(nodemailer, 'createTransport');
|
||||
|
||||
new EmailService(
|
||||
{
|
||||
host: 'smtp.unleash.test',
|
||||
port: 9999,
|
||||
secure: false,
|
||||
sender: 'noreply@getunleash.ai',
|
||||
transportOptions: {
|
||||
tls: {
|
||||
rejectUnauthorized: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
noLoggerProvider,
|
||||
);
|
||||
|
||||
expect(spy).toHaveBeenCalledWith({
|
||||
auth: {
|
||||
user: '',
|
||||
pass: '',
|
||||
},
|
||||
host: 'smtp.unleash.test',
|
||||
port: 9999,
|
||||
secure: false,
|
||||
tls: {
|
||||
rejectUnauthorized: true,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
@ -21,15 +21,6 @@ export enum TransporterType {
|
||||
JSON = 'json',
|
||||
}
|
||||
|
||||
export interface IEmailOptions {
|
||||
host: string;
|
||||
port: number;
|
||||
secure: boolean;
|
||||
sender: string;
|
||||
auth: IAuthOptions;
|
||||
transporterType: TransporterType;
|
||||
}
|
||||
|
||||
export interface IEmailEnvelope {
|
||||
from: string;
|
||||
to: string;
|
||||
@ -57,10 +48,16 @@ export class EmailService {
|
||||
if (email.host === 'test') {
|
||||
this.mailer = createTransport({ jsonTransport: true });
|
||||
} else {
|
||||
const connectionString = `${email.smtpuser}:${email.smtppass}@${email.host}:${email.port}`;
|
||||
this.mailer = email.secure
|
||||
? createTransport(`smtps://${connectionString}`)
|
||||
: createTransport(`smtp://${connectionString}`);
|
||||
this.mailer = createTransport({
|
||||
host: email.host,
|
||||
port: email.port,
|
||||
secure: email.secure,
|
||||
auth: {
|
||||
user: email.smtpuser ?? '',
|
||||
pass: email.smtppass ?? '',
|
||||
},
|
||||
...email.transportOptions,
|
||||
});
|
||||
}
|
||||
this.logger.info(
|
||||
`Initialized transport to ${email.host} on port ${email.port} with user: ${email.smtpuser}`,
|
||||
|
@ -2,6 +2,7 @@ import EventEmitter from 'events';
|
||||
import { LogLevel, LogProvider } from '../logger';
|
||||
import { ILegacyApiTokenCreate } from './models/api-token';
|
||||
import { IExperimentalOptions } from '../experimental';
|
||||
import SMTPTransport from 'nodemailer/lib/smtp-transport';
|
||||
|
||||
export type EventHook = (eventName: string, data: object) => void;
|
||||
|
||||
@ -111,6 +112,7 @@ export interface IEmailOption {
|
||||
sender: string;
|
||||
smtpuser?: string;
|
||||
smtppass?: string;
|
||||
transportOptions?: SMTPTransport.Options;
|
||||
}
|
||||
|
||||
export interface IListeningPipe {
|
||||
|
Loading…
Reference in New Issue
Block a user