A
A
Alexander Kusak2020-10-14 17:55:57
Node.js
Alexander Kusak, 2020-10-14 17:55:57

Nest mailer throws an error Mailer send Error: Error: Missing credentials for "PLAIN", Why?

Added a module to Nest for sending messages in this form:

SenderModule

import { Module, HttpModule, HttpService } from '@nestjs/common';
import { SenderService } from './sender.service';
import { MailerModule } from '@nestjs-modules/mailer';
import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter';

@Module({
  imports: [
    MailerModule.forRootAsync({
      useFactory: () => ({
        transport: {
          service: 'gmail',
          auth: {
            user: process.env.MAIL_ADDRESS,
            pass: process.env.MAIL_PASSWORD,
          },
        },
        defaults: {
          from: '"vlntmgmt" <[email protected]>',
        },
        template: {
          dir: __dirname + '/templates',
          adapter: new HandlebarsAdapter(),
          options: {
            strict: true,
          },
        },
      })
    }),
  ],
  providers: [SenderService],
  exports: [SenderService]
})
export class SenderModule { }


Service file of this module
import { Injectable, HttpService } from '@nestjs/common';
import { MailerService } from '@nestjs-modules/mailer';

@Injectable()
export class SenderService {
  constructor(private readonly mailerService: MailerService, private httpService: HttpService) { }

  async sendEmail(email: string, message: string, messageHTML?: string) {
    await this.mailerService.sendMail({
      to: email,
      from: '"vlntmgmt" <[email protected]>',
      subject: 'vlntmgmt noreply message',
      text: message,
      html: `<b>${messageHTML ? messageHTML : message}</b>`
    })
      .then(() => { console.log("Mailer sended to", email) })
      .catch((err) => { console.log("Mailer send Error:", err) });
    return true;
  }
}


When submitting, I get an error with the logs:
Mailer send Error: Error: Missing credentials for "PLAIN"
     at SMTPConnection._formatError (/node_modules/nodemailer/lib/smtp-connection/index.js:784:19)
     at SMTPConnection.login (/node_modules/nodemailer/lib/smtp-connection/index.js:448:38)
     at /node_modules/nodemailer/lib/smtp-transport/index.js:271:32
     at SMTPConnection.<anonymous> (/node_modules/nodemailer/lib/smtp-connection/index.js:215:17)
     at Object.onceWrapper (events.js:420:28)
     at SMTPConnection.emit (events.js:314:20)
     at SMTPConnection._actionEHLO (/node_modules/nodemailer/lib/smtp-connection/index.js:1313:14)
     at SMTPConnection._processResponse (/node_modules/nodemailer/lib/smtp-connection/index.js:942:20)
     at SMTPConnection._onData (/node_modules/nodemailer/lib/smtp-connection/index.js:749:14)
     at TLSSocket.SMTPConnection._onSocketData (/node_modules/nodemailer/lib/smtp-connection/index.js:195:44) {
   code: 'EAUTH',
   command: 'API'
 }


Disabled check for insecure connections in mail. Mail and password from the mail, respectively, are correct.
What could be the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex, 2020-10-15
@DreamReal

possible answers
Most likely there are not enough tokens

W
weksik, 2021-08-08
@weksik

Console processes.env.MAIL_ADDRESS, will your result be or undefined?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question