38 lines
879 B
TypeScript
38 lines
879 B
TypeScript
import { Inject, Injectable } from '@nestjs/common';
|
|
import * as nodemailer from 'nodemailer';
|
|
import { ConfigurationService } from 'src/modules/config/config.service';
|
|
import { EmailTemplate } from './email.template';
|
|
|
|
@Injectable()
|
|
export class EmailService {
|
|
constructor(
|
|
@Inject('EMAIL_TRANSPORT')
|
|
private transport: nodemailer.Transporter,
|
|
private config: ConfigurationService,
|
|
) {}
|
|
|
|
public async sendEmail(
|
|
to: string,
|
|
subject: string,
|
|
text: string,
|
|
html?: string,
|
|
from = this.config.get<string>('email.from'),
|
|
): 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);
|
|
}
|
|
}
|