A simple Next.js 15 project that uses Nodemailer to send emails from a contact form. Built with Tailwind CSS for a clean design and easy customization.
✅ Beautifully styled contact form
✅ Sends emails using Nodemailer & Gmail
✅ Serverless API route for handling form submissions
✅ Input validation & success/error messages
git clone https://github.com/your-username/nodemailer-example.git
cd nodemailer-example
npm install
Create a .env.local
file in the root directory and add:
[email protected]
EMAIL_PASS=your-app-password
[email protected]
⚠️ Important: Gmail requires App Passwords instead of your regular password.
👉 Follow this guide to generate one.
npm run dev
Now, visit http://localhost:3000
in your browser.
/nodemailer-example
├── app/
│ ├── api/sendEmail/route.js # API to send emails
│ ├── components/ContactForm.js # The contact form component
│ ├── page.js # The main page that renders the form
├── .env.local # Stores email credentials
├── package.json
├── next.config.js
├── README.md
🔹 Email not sending?
🔹 Still not working?
console.log(error)
inside the catch
block in route.js
. 🔹 Add reCAPTCHA for spam protection
🔹 Support attachments in emails
🔹 Store form submissions in a database
Feel free to fork this repo, add features, and submit a pull request!
This project is open-source under the MIT License.
🔥 Happy Coding! 🚀