import * as nodemailer from "nodemailer"; //config nodemailer transporter using environment variables const transporter = nodemailer.createTransport({ host: `${process.env.AWS_SMTP_HOST}` , auth: { user: `${process.env.AWS_ACCESS_KEY_ID}`, pass: `${process.env.AWS_SECRET_ACCESS_KEY}` } }); export const emailSender = async (data) => { try { const response = await transporter.sendMail({ from: process.env.EMAIL_FROM, to: process.env.EMAIL_TO || data.email, subject: process.env.EMAIL_SUBJECT || data.subject, html: `<DOCTYPE html> <html> <body> ${data.message} </body> </html> ` }); return response?.messageId ? { success: true } : { success: false, error: "Failed to send email" }; } catch ( error ){ console.log("ERROR", error.message); return { success: false, error: error.message }; } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter