Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

verifyTransporter function doesn't check if transport.verify is defined #1144

Open
mahdichaari01 opened this issue Mar 21, 2024 · 0 comments

Comments

@mahdichaari01
Copy link

mahdichaari01 commented Mar 21, 2024

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:

  1. use this valid nodemailer config in the module config:
MailerModule.forRoot({
        transport: { streamTransport: true, newline: 'windows' },
        options: {},
        template: {
          adapter: new MjmlAdapter('ejs', { inlineCssEnabled: true }),
        },
      }),
  1. 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;
                }
            };
        });


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant