verifyTransporter function doesn't check if transport.verify is defined
mahdichaari01 opened this issue · 0 comments
mahdichaari01 commented
Describe the bug
transport.verify may return void, or false however it's handled as a promise. This issue arises when using the StreamTransport which has a verify function that always returns false.
To Reproduce
Steps to reproduce the behavior:
- use this valid nodemailer config in the module config:
MailerModule.forRoot({
transport: { streamTransport: true, newline: 'windows' },
options: {},
template: {
adapter: new MjmlAdapter('ejs', { inlineCssEnabled: true }),
},
}),
- run the application
Expected behavior
It should run perfectly
Additional context
The problem lies in a wrong nodemailer typing. Which describes that verify must return either void or Promise. However the Mail class in nodemailer implementation checks if verify is not defined and implements one that logs undefined and returns false.
This is the transport interface from @types/nodemailer
export interface Transport<T = any> {
mailer?: Transporter<T> | undefined;
name: string;
version: string;
send(mail: MailMessage<T>, callback: (err: Error | null, info: T) => void): void;
verify?(callback: (err: Error | null, success: true) => void): void;
verify?(): Promise<true>;
close?(): void;
}
This is the node mailer snippet that creates the verify method
['close', 'isIdle', 'verify'].forEach(method => {
this[method] = (...args) => {
if (typeof this.transporter[method] === 'function') {
if (method === 'verify' && typeof this.getSocket === 'function') {
this.transporter.getSocket = this.getSocket;
this.getSocket = false;
}
return this.transporter[method](...args);
} else {
this.logger.warn(
{
tnx: 'transport',
methodName: method
},
'Non existing method %s called for transport',
method
);
return false;
}
};
});