Next.Js Pages Router
To use easymailer with Next.js Pages router
- in your nextjs app, install the
easymailer
package
npm i @xeuxdev/easymailer
import the easymailer package into your api route
api/email/index.js/ts
import { sendMail } from "@xeuxdev/easymailer"
-
Don't forget to add your environment variables, to see how you can do that go to usage
-
below is an example code
import { sendMail } from "@xeuxdev/easymailer"
import { NextApiRequest, NextApiResponse } from "next"
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
const { email } = req.body
const response = await sendMail({
message: {
from: "xeux nextjs pages router",
html: "Test email from nextjs pages router",
subject: "Next.js pages router example",
cc: email,
},
transport: {
service: "gmail",
// grouped: false,
// secure: true,
// pool: false,
},
})
res
.status(response.status == "failed" ? 500 : 200)
.json({ message: response.message })
}