mailer
, в ней есть папка templates
, а вней есть файл confirm-mail.ejs
import {Injectable, Logger} from '@nestjs/common';
import {UserService} from "../user/user.service";
import {JwtService} from "@nestjs/jwt";
import {MailerService} from "@nestjs-modules/mailer";
import * as path from "path";
@Injectable()
export class MailService {
constructor(private readonly mailerService: MailerService) {}
async sendConfirmMail(user) {
this.mailerService
.sendMail({
to: user.email, // list of receivers
subject: 'Авторизация на сайте ' + process.env.API_URL, // Subject line
text: 'welcome', // plaintext body
template: path.join(__dirname, '/../mailer/templates', 'confirm-mail.ejs'),
context: {
urlConfirmAddress: user.activationLink
}
})
.then(() => {})
.catch((error) => {
Logger.error(error)
});
}
}
ERROR Error: ENOENT: no such file or directory, open 'confirm-mail.ejs'
@Module({
imports: [MailerModule.forRoot({
transport: environment.SmtpDetails,
defaults: {
from: environment.SmtpEmail,
},
template: {
dir: path,
adapter: new EjsAdapter(),
options: {
strict: true,
},
},
})
})
const emailData = await this.mailerService.sendMail({
to: emailTo,
from: 'user@test.com',
subject: 'Testing Nest Mailermodule with template',
template: 'notification',
context: { // Data to be sent to template engine.
"code": 'cf1a3f828287',
"username": 'john doe',
},
});