LK
переключение между потоками
Size: a a a
LK
AM
AM
DB
LK
DB
S
npx nestjs-moduleshttps://github.com/svtslv/nestjs-modules
AM
S
VK
S
VK
NodemailerModule.forRootAsync({
from: configInstance.email.from,
host: configInstance.email.host,
port: configInstance.email.port,
auth: {
user: configInstance.email.auth.user,
pass: configInstance.email.auth.pass,
},
templatesPath: path.join(__dirname, '..', 'email-templates'),
renderStrategy: new EjsStrategy(),
useTestAccount: configInstance.email.testMode,
}),
import * as ejs from 'ejs';
import { RenderStrategyInterface } from '../interfaces';
export class EjsStrategy implements RenderStrategyInterface {
async render(templatePath: string, context?: any): Promise<string> {
return ejs.renderFile(templatePath, { context });
}
}
import * as path from 'path';
import { Injectable, Inject } from '@nestjs/common';
import { SentMessageInfo, Transporter, SendMailOptions, getTestMessageUrl } from 'nodemailer';
import { NODEMAILER_OPTIONS, NODEMAILER_TRANSPORT } from './constants';
import { NodemailerAsyncOptions } from './interfaces';
@Injectable()
export class NodemailerService {
private lastEmail: SendMailOptions = null;
constructor(
@Inject(NODEMAILER_OPTIONS)
private readonly options: NodemailerAsyncOptions,
@Inject(NODEMAILER_TRANSPORT) private readonly nodemailer: Transporter,
) {}
getLastEmail() {
return this.lastEmail;
}
getTestMessageUrl(info: SentMessageInfo) {
return getTestMessageUrl(info);
}
async send(options: {
templateName: string;
to: string;
context?: any;
subject?: string;
}): Promise<SentMessageInfo> {
const templatePath = path.join(
this.options.templatesPath,
options.templateName,
);
const email = await this.options.renderStrategy.render(
templatePath,
options.context,
);
const emailOptions: SendMailOptions = {
to: options.to,
html: email,
subject: options.subject,
};
// Store last email for E2E tests
this.lastEmail = emailOptions;
return this.nodemailer.sendMail(emailOptions);
}
}VK
VK
S
VK
VK
NodemailerModule.forRootAsync({
from: configInstance.email.from,
host: configInstance.email.host,
port: configInstance.email.port,
auth: {
user: configInstance.email.auth.user,
pass: configInstance.email.auth.pass,
},
templatesPath: path.join(__dirname, '..', 'email-templates'),
renderStrategy: new EjsStrategy(),
useTestAccount: configInstance.email.testMode,
}),VK
DZ