Skip to content

Instantly share code, notes, and snippets.

@SuperC03
Last active March 2, 2020 19:05
Show Gist options
  • Save SuperC03/98ed8ae7bc8bf10ecbb6e1b7f131ca25 to your computer and use it in GitHub Desktop.
Save SuperC03/98ed8ae7bc8bf10ecbb6e1b7f131ca25 to your computer and use it in GitHub Desktop.
import nodemailer from 'nodemailer';
export class GMailService {
private _transporter: nodemailer.Transporter;
constructor(username: string, password: string) {
this._transporter = nodemailer.createTransport(
`smtps://<username>%40gmail.com:<password>@smtp.gmail.com`
);
}
sendMail(to: string, subject: string, content: string) {
let options = {
from: 'from_test@gmail.com',
to: to,
subject: subject,
text: content
}
this._transporter.sendMail(
options, (error, info) => {
if (err) {
return console.error(`Mailer Error: ${err}`);
}
console.log(`Message Sent ${info.response}`);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment