Last active
March 2, 2020 19:05
-
-
Save SuperC03/98ed8ae7bc8bf10ecbb6e1b7f131ca25 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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