Next.Js App Router
To use easymailer with Next.js App router
- in your nextjs app, install the
easymailer
package
npm i @xeuxdev/easymailer
import the easymailer package into your api route
api/email/route.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
export async function POST(request: Request) {
const { email } = await request.json()
const response = await sendMail({
message: {
from: "xeux nextjs app router",
html: "Test email from nextjs app router",
subject: "Next.js App router example",
cc: email,
},
transport: {
service: "gmail",
// grouped: false,
// secure: true,
// pool: false,
},
})
return NextResponse.json(
{ message: response.message },
{
status: response.status == "failed" ? 500 : 200,
}
)
}