Добавил в Nest модуль для отправки сообщений в таком виде:
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" <vlnt@mydomain.ru>',
},
template: {
dir: __dirname + '/templates',
adapter: new HandlebarsAdapter(),
options: {
strict: true,
},
},
})
}),
],
providers: [SenderService],
exports: [SenderService]
})
export class SenderModule { }
Сервис файл данного модуля
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" <vlnt@mydomain.ru>',
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;
}
}
При отправке получаю ошибку с логами:
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'
}
У почты отключил проверку не безопасных соединений. Почта и пароль от почты соответственно верные.
В чем может быть проблема?