4.2 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	Gmail Contact Form Setup Guide
This guide will help you configure your contact form to send emails to your company Gmail inbox.
Prerequisites
- A Gmail account for your company
 - Access to Google Account settings
 - Basic understanding of environment variables
 
Step 1: Enable 2-Factor Authentication
- Go to Google Account Settings
 - Navigate to Security → 2-Step Verification
 - Follow the prompts to enable 2FA if not already enabled
 - Note: App passwords require 2FA to be enabled
 
Step 2: Generate Gmail App Password
- Go to Google Account Settings
 - Navigate to Security → 2-Step Verification → App passwords
 - Select Mail as the app and Other as the device
 - Enter "OurWorld Contact Form" as the device name
 - Click Generate
 - Important: Copy the 16-character app password immediately (you won't see it again)
 
Step 3: Configure Environment Variables
- Open the 
.env.localfile in your project root - Replace the placeholder values with your actual credentials:
 
# Your Gmail address (the one that will send emails)
GMAIL_USER=your-company-email@gmail.com
# The 16-character app password you generated (no spaces)
GMAIL_APP_PASSWORD=abcdabcdabcdabcd
# Email address where contact form submissions will be sent
COMPANY_EMAIL=info@ourworld.tf
Step 4: Security Considerations
Environment Variables
- Never commit 
.env.localto version control - The 
.env.localfile is already in.gitignore - Use different environment variables for production deployment
 
Production Deployment
For production (Vercel, Netlify, etc.), add these environment variables in your hosting platform's dashboard:
GMAIL_USERGMAIL_APP_PASSWORDCOMPANY_EMAIL
Step 5: Testing the Setup
- 
Start your development server:
npm run dev - 
Navigate to
/contactpage - 
Fill out and submit the contact form
 - 
Check your Gmail inbox for the contact form submission
 
Troubleshooting
Common Issues
"Authentication failed" error:
- Verify 2FA is enabled on your Google account
 - Double-check the app password (no spaces, 16 characters)
 - Ensure you're using the app password, not your regular Gmail password
 
"Invalid credentials" error:
- Verify the 
GMAIL_USERemail address is correct - Check that the app password is correctly copied
 
Emails not being received:
- Check your spam/junk folder
 - Verify the 
COMPANY_EMAILaddress is correct - Test with a different recipient email
 
"Module not found" error:
- Ensure nodemailer is installed: 
npm install nodemailer @types/nodemailer 
Email Format
The contact form sends emails with:
- Subject: "New Contact Form Submission from [First Name] [Last Name]"
 - From: Your Gmail address (GMAIL_USER)
 - To: Company email address (COMPANY_EMAIL)
 - Content: Formatted HTML and plain text versions
 
Security Best Practices
- Use App Passwords: Never use your main Gmail password
 - Limit Access: Only share credentials with necessary team members
 - Regular Rotation: Consider rotating app passwords periodically
 - Monitor Usage: Check Gmail's security activity regularly
 - Environment Separation: Use different credentials for development/production
 
Alternative Solutions
If you prefer not to use Gmail directly, consider these alternatives:
- EmailJS: Client-side email service
 - Formspree: Form handling service
 - SendGrid: Professional email API
 - Mailgun: Email delivery service
 - Resend: Modern email API
 
Support
If you encounter issues:
- Check the browser console for error messages
 - Review the server logs for API errors
 - Verify all environment variables are set correctly
 - Test with a simple email first
 
File Structure
project/
├── .env.local                 # Environment variables (not in git)
├── src/app/api/contact/       # API route for form submission
├── src/components/ContactHero.tsx  # Contact form component
└── docs/gmail-setup-guide.md # This guide
Important: Keep your app password secure and never share it publicly. If compromised, revoke it immediately in your Google Account settings and generate a new one.