UNPKG

@profitsniper/email

Version:

While developing with Typescript and Node.js is awesome, **setting up a new project is painful**. This minimal and modern starter repo is here to help you get started with Node.js and Typecript without the pain.

31 lines (28 loc) 824 B
import type { EmailPlugin, SendEmailEvent } from '@profitsniper/shared' import stringify from 'fast-safe-stringify' import mailer from 'nodemailer' const sendEmail: EmailPlugin = async (event: SendEmailEvent) => { try { const transport = mailer.createTransport({ service: event.service, auth: event.auth }) const addr = `${event.auth.user}@${event.service.toLowerCase()}.com` const info = await transport.sendMail({ from: addr, to: addr, subject: event.subject, text: JSON.stringify(event.alert, null, 2) }) return { id: info.messageId, accepted: info.accepted, rejected: info.rejected, pending: info.pending, response: info.response } } catch (error) { return { error: stringify(error) } } } export default sendEmail