How to Send Stunning Email Reports Using Nodemailer NextJS

Sending emails directly from your Next.js app? Yes, you heard that right! In this post, I’ll explain how I used Next.js and Nodemailer to send personalized score reports for my Circle Clicker Game. The twist? The emails are so polished that they’ll have your players coming back for more!

Oh, and the best part? The entire project is hosted for free on Vercel!

Ready to dive in? Let’s go!

nodemailer

Circle Clicker Game: The Setup

Imagine this: A fast-paced browser game where players click circles for points while racing against the clock. Once the game ends, the scores are saved and showcased in a sleek leaderboard. But I didn’t stop there. I wanted players to receive their scores directly in their inboxes — complete with a polished HTML email showcasing their performance.

Here’s a glimpse of what we’re building:

▪️Front-end: A game UI built with Next.js, Material UI, and Framer Motion.
▪️Back-end: A Next.js App Router API that uses Nodemailer to send email reports.
▪️Hosting: Deployed on Vercel with its free Hobby plan.

Circle Clicker Game

Why Nodemailer?

For tasks like sending emails, Nodemailer is a no-brainer. It’s:

▪️Easy to set up with any SMTP provider (I used Gmail).
▪️Flexible for crafting stunning HTML emails.
▪️Reliable for production use.

With Nodemailer, I was able to generate an eye-catching HTML email complete with:

▪️Player name.
▪️Detailed score report.
▪️Dynamic star ratings are based on their performance.

How It Works: Sending Emails with Nodemailer

1. Setting Up the Email Dialog

Players can trigger the email directly from the game’s leaderboard using a Material UI dialog:

Setting Up the Email Dialog

Explanation:

1. API Call:

▪️This snippet makes a POST request to /api/sendEmail, sending the player’s email and scores as JSON.

2. Asynchronous:

▪️It uses await to ensure the request completes before proceeding.

Email Dialog

2. Back-End: API Route to Send Emails

The backend uses Nodemailer to send the emails. Here’s a key part of the implementation:

API Route to Send Emails

Explanation:

1. Transporter Configuration:

▪️This sets up the SMTP connection using Gmail.
▪️EMAIL_USER and EMAIL_PASS are stored in environment variables for security.

2. Authentication:

▪️Gmail requires an app password (not your regular password) for sending emails via Nodemailer.

Next, we define the email’s content:

Const Html

Explanation:

1. HTML Structure:

▪️The email includes a heading and a dynamic table with rows generated from the scores array.

2. Dynamic Content:

▪️scores.map() loops through the scores and generates a row for each player.

Finally, send the email:

await transporter

Explanation:

1. Email Details:

▪️from: The sender’s email address.
▪️to: The recipient’s email (provided by the user).
▪️subject: The email subject line.
▪️html: The body content we created earlier.

2. Sending:

▪️sendMail triggers the email to be sent to the specified recipient.

Want to Implement Email Features Like This? Check Our Backend Solutions

The Result: Sleek Email Reports

Sleek Email Reports

The emails include:

▪️Dynamic Score Tables: A detailed breakdown of player performance.
▪️Polished Design: Styled with inline HTML and CSS.
▪️Call to Action: Encourages players to replay the game.

Deployed for Free on Vercel

Thanks to Vercel’s Hobby Plan, this entire app, including the Nodemailer integration, is hosted for free! Deployment was as simple as running:

Vercel Deploy

And just like that, the app will be live at the link provided by Vercel.

Takeaways

▪️Next.js App Router simplifies backend and API development.
▪️Nodemailer makes it easy to craft and send professional emails.
▪️Vercel’s free hosting is perfect for deploying small apps with minimal effort.

Whether you’re building a game, a dashboard, or an app that needs email integration, this approach will take your project to the next level. Give it a try!

coma

Conclusion

Building personalized email reports using Nodemailer and Next.js not only enhances the user experience but also adds a polished touch to your app’s communication. From designing engaging score reports to sending them seamlessly, this approach showcases the power of combining front-end interactivity with backend automation. Whether you’re making a game or a utility tool, this integration can make your project stand out. And the best part? You can do it all for free with Vercel.

If you’re planning to implement similar features, this setup offers a great starting point. With simple API routes, secure SMTP setup, and HTML email templates, you can deliver real-time, branded updates to your users. Nodemailer handles the heavy lifting while Next.js ties it all together. So go ahead—bring your app to life with smart, automated email experiences!

Keep Reading

Keep Reading

  • Service
  • Career
  • Let's create something together!

  • We’re looking for the best. Are you in?