Skip to content

Instantly share code, notes, and snippets.

@olafkotur
Created January 29, 2020 20:25
Show Gist options
  • Save olafkotur/84468c9cfe0f10f9c330fe330100d4b8 to your computer and use it in GitHub Desktop.
Save olafkotur/84468c9cfe0f10f9c330fe330100d4b8 to your computer and use it in GitHub Desktop.
Email service for sending out emails via nodemailer
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