Created
January 29, 2020 20:25
-
-
Save olafkotur/84468c9cfe0f10f9c330fe330100d4b8 to your computer and use it in GitHub Desktop.
Email service for sending out emails via nodemailer
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 const EmailService = { | |
send: async (subject: string, to: string, body: string) => { | |
const transporter = nodemailer.createTransport({ | |
host: 'smtp.gmail.com', | |
port: 587, | |
secure: false, | |
auth: { | |
user: process.env.EMAIL_ADDRESS || '', | |
pass: process.env.EMAIL_PASSWORD || '' | |
} | |
}); | |
await transporter.sendMail({ | |
from: `"example" <[email protected]>`, | |
to, | |
subject, | |
html: body | |
}); | |
console.log(`EmailService: Sent email to ${to}`); | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment