A comprehensive serverless email API built with Nodemailer for Vercel deployment. This API handles contact form submissions from the NodeWave Vue.js frontend with advanced debugging, validation, and multiple email service support.
- β Serverless Architecture - Zero-config deployment to Vercel
- β Multiple Email Services - Gmail, Outlook, Yahoo, or custom SMTP
- β Comprehensive Validation - Input sanitization and error handling
- β Debug Mode - Advanced logging controlled by environment variables
- β CORS Support - Ready for frontend integration
- β HTML & Text Emails - Professional email templates
- β Security First - No credentials in code, environment-based config
nodewave_email/
βββ api/
β βββ contact.js # Main serverless function
βββ public/ # Static assets (required by Vercel)
βββ package.json # Dependencies and scripts
βββ vercel.json # Vercel deployment configuration
βββ .env.example # Environment variables template
βββ .env # Local development config (git-ignored)
βββ .gitignore # Git ignore patterns
βββ test-api.sh # API testing script
βββ README.md
npm installcp .env.example .envEdit .env with your email service credentials:
# Email Service Configuration
EMAIL_SERVICE=gmail # gmail, outlook, yahoo, or smtp
EMAIL_USER=your-email@gmail.com # Your email address
EMAIL_PASS=your-app-password # App password (not regular password)
EMAIL_TO=contact@nodewave.com # Recipient email address
# Optional: Custom SMTP (if EMAIL_SERVICE=smtp)
EMAIL_HOST=smtp.your-provider.com
EMAIL_PORT=587
# Debug Mode (optional)
DEBUG_APP=false # Set to 'true' for detailed logging- Enable 2-Factor Authentication on your Gmail account
- Generate an App Password:
- Go to Google Account Settings
- Security β 2-Step Verification β App passwords
- Select "Mail" and generate password
- Use the generated 16-character password in
EMAIL_PASS
# Start local development server
npm run dev
# or
vercel devThe API will be available at http://localhost:3000/api/contact
# Run the test script
./test-api.sh
# Or test manually with curl
curl -X POST http://localhost:3000/api/contact \
-H "Content-Type: application/json" \
-d '{
"firstName": "John",
"lastName": "Doe",
"email": "john@example.com",
"phone": "+1 (555) 123-4567",
"subject": "Test Subject",
"budget": "Under $10K",
"message": "This is a test message.",
"newsletter": true
}'vercel --prod- Go to your Vercel dashboard
- Select your project
- Navigate to Settings β Environment Variables
- Add all required environment variables:
| Variable | Value | Environment |
|---|---|---|
EMAIL_SERVICE |
gmail |
Production, Preview, Development |
EMAIL_USER |
your-email@gmail.com |
Production, Preview, Development |
EMAIL_PASS |
your-app-password |
Production, Preview, Development |
EMAIL_TO |
contact@nodewave.com |
Production, Preview, Development |
DEBUG_APP |
false |
Production (set to true for debugging) |
Sends a contact form email with comprehensive validation and error handling.
{
"firstName": "John",
"lastName": "Doe",
"email": "john@example.com",
"phone": "+1 (555) 123-4567",
"subject": "General Inquiry",
"budget": "Under $10K",
"message": "Hello, I'm interested in your IoT solutions.",
"newsletter": true
}firstName(string): Contact's first namelastName(string): Contact's last nameemail(string): Valid email addresssubject(string): Subject of the inquirymessage(string): Message content (minimum 1 character)
phone(string): Phone numberbudget(string): Budget range selectionnewsletter(boolean): Newsletter subscription preference
{
"success": true,
"message": "Email sent successfully"
}With Debug Mode:
{
"success": true,
"message": "Email sent successfully",
"debug": {
"messageId": "<unique-message-id>",
"accepted": ["contact@nodewave.com"],
"rejected": [],
"response": "250 Message accepted"
}
}Validation Error (400):
{
"success": false,
"error": "First name is required"
}Server Error (500):
{
"success": false,
"error": "Email authentication failed - check your credentials"
}With Debug Mode:
{
"success": false,
"error": "Email authentication failed - check your credentials",
"debug": {
"originalError": "Invalid login: 535-5.7.8 Username and Password not accepted",
"code": "EAUTH",
"command": "AUTH LOGIN"
}
}| Variable | Description | Required | Example |
|---|---|---|---|
EMAIL_SERVICE |
Email service provider | β | gmail, outlook, yahoo, smtp |
EMAIL_USER |
Email account username | β | your-email@gmail.com |
EMAIL_PASS |
Email account password/app password | β | abcdefghijklmnop |
EMAIL_TO |
Recipient email address | β | your-email@gmail.com |
EMAIL_HOST |
SMTP host (for custom SMTP) | If EMAIL_SERVICE=smtp |
smtp.gmail.com |
EMAIL_PORT |
SMTP port (for custom SMTP) | If EMAIL_SERVICE=smtp |
587 |
DEBUG_APP |
Enable comprehensive logging | β | true or false |
# Test with all fields
curl -X POST http://localhost:3000/api/contact \
-H "Content-Type: application/json" \
-d '{
"firstName": "Test",
"lastName": "User",
"email": "test@example.com",
"phone": "+1 (555) 123-4567",
"subject": "API Test",
"budget": "Under $10K",
"message": "This is a comprehensive test of the API.",
"newsletter": true
}'
# Test validation errors
curl -X POST http://localhost:3000/api/contact \
-H "Content-Type: application/json" \
-d '{
"firstName": "",
"email": "invalid-email"
}'# Run the included test script
./test-api.sh-
Set the API URL in your Vue.js environment:
# .env.local VITE_EMAIL_API_URL=https://your-api.vercel.app/api/contact