Skip to content

Instantly share code, notes, and snippets.

@ancyrweb
Created October 3, 2022 03:46
Show Gist options
  • Save ancyrweb/757262beeb2dd77df1746604be3ddfc1 to your computer and use it in GitHub Desktop.
Save ancyrweb/757262beeb2dd77df1746604be3ddfc1 to your computer and use it in GitHub Desktop.
import { Injectable } from '@nestjs/common';
import * as nodemailer from 'nodemailer';
import Mail from 'nodemailer/lib/mailer';
export type SendEmailData = {
subject: string;
from: string;
to: string;
body: string;
};
@Injectable()
export class EmailService {
private transport: Mail;
constructor() {
this.transport = nodemailer.createTransport({
host: 'localhost',
port: 7002,
});
}
async send(data: SendEmailData) {
return this.transport.sendMail({
from: data.from,
to: data.to,
subject: data.subject,
html: data.body,
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment