Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
✨ Render and send emails
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Oct 22, 2020
1 parent 45288fa commit 7b6902d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/modules/email/email.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export interface EmailConfig {

export interface EmailOptions {
template?: string;
data?: Record<string, any>;
}
10 changes: 10 additions & 0 deletions src/modules/email/email.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Mail from 'nodemailer/lib/mailer';
import { promises as fs } from 'fs';
import { join } from 'path';
import mem from 'mem';
import { render } from '@staart/mustache-markdown';

@Injectable()
export class EmailService {
Expand Down Expand Up @@ -45,6 +46,15 @@ export class EmailService {
private async sendEmail(options: Mail.Options & EmailOptions) {
if (options.template) {
const template = await this.readTemplate(options.template);
const [markdown, html] = render(template, options.data);
options.html = html;
options.text = markdown;
options.alternatives = [
{
contentType: 'text/x-web-markdown',
content: markdown,
},
];
}
return this.transport.sendMail(options);
}
Expand Down

0 comments on commit 7b6902d

Please sign in to comment.