Next.js Discord

Discord Forum

How do I export nodemailer to use in other pages?

Unanswered
Giant panda posted this in #help-forum
Open in Discord
Giant pandaOP
"use strict"; const nodemailer = require("nodemailer"); const transporter = nodemailer.createTransport({ host: "smtp.gmail.com", port: 465, secure: true, auth: { user: "process.env.EMAIL", pass: "process.env.PASS", }, }); async function main() { const info = await transporter.sendMail({ from: 'process.env.EMAIL', to: "test@gmail.com", subject: "Hello ✔", text: "Test Mail ", html: "<b>Hello world?</b>", }); console.log("Message sent: %s", info.messageId); } main().catch(console.error);

This is my mail.js file. I would like to be able to export it so I can reuse it in other pages to send mails. But when I try to use module.exports, it says can't resolve dns.

2 Replies

Giant pandaOP
I was able to make an api call instead with axios.post
But would still like to know what the problem is with module.exports