icynet-auth-server/src/modules/objects/email/email.service.ts

36 lines
746 B
TypeScript

import { Inject, Injectable } from '@nestjs/common';
import * as nodemailer from 'nodemailer';
import { EmailTemplate } from './email.template';
@Injectable()
export class EmailService {
constructor(
@Inject('EMAIL_TRANSPORT')
private transport: nodemailer.Transporter,
) {}
public async sendEmail(
to: string,
subject: string,
text: string,
html?: string,
from = 'no-reply@icynet.eu',
): Promise<any> {
return this.transport.sendMail({
to,
subject,
text,
html,
from,
});
}
public async sendEmailTemplate(
to: string,
subject: string,
message: EmailTemplate,
): Promise<any> {
return this.sendEmail(to, subject, message.text, message.html);
}
}