This guide provides step-by-step instructions for setting up the SendGrid email integration for the contact form.
- A SendGrid account (free tier available at https://sendgrid.com)
- A Vercel account (free tier available at https://vercel.com)
- Access to this GitHub repository
-
Sign up for SendGrid
- Go to https://sendgrid.com
- Create a free account (allows 100 emails/day)
- Verify your email address
-
Create an API Key
- Log in to SendGrid dashboard
- Go to Settings → API Keys
- Click "Create API Key"
- Name it (e.g., "Portfolio Contact Form")
- Select "Full Access" or "Mail Send" permissions
- Click "Create & View"
- IMPORTANT: Copy the API key immediately - you won't be able to see it again!
-
Single Sender Verification (Recommended for personal use)
- In SendGrid dashboard, go to Settings → Sender Authentication
- Click "Get Started" under "Verify a Single Sender"
- Fill in your email details (use the email where you want to receive messages)
- Click "Create"
- Check your email and click the verification link
- Wait for verification to complete
-
Domain Authentication (Optional, for production)
- Go to Settings → Sender Authentication
- Click "Authenticate Your Domain"
- Follow the DNS configuration steps
- This provides better email deliverability
-
Connect Repository to Vercel
- Go to https://vercel.com
- Click "New Project"
- Import this GitHub repository
- Vercel will automatically detect it as a Vite project
-
Configure Environment Variables
- Before deploying, go to "Environment Variables" section
- Add the following variables:
SENDGRID_API_KEY=SG.xxxxxxxxxxxxxxxxxxxxxxxxxxxxx SENDGRID_FROM_EMAIL=your-verified-email@example.com CONTACT_EMAIL=levanijincharadze@outlook.com - Replace the values with your actual SendGrid API key and verified email
- Click "Deploy"
-
Verify Deployment
- Wait for deployment to complete
- Visit your Vercel URL
- Test the contact form by filling it out and clicking "Send"
- Check your email inbox for the message
-
Add Custom Domain in Vercel
- Go to your project settings in Vercel
- Click "Domains"
- Add your custom domain (e.g., levanijintcharadze.dev)
- Follow the DNS configuration instructions
-
Update CNAME File
- The CNAME file in the repository should contain your custom domain
- Commit and push any changes
-
Check SendGrid API Key
- Verify the API key is correct in Vercel environment variables
- Ensure the API key has "Mail Send" permissions
-
Check Sender Email
- Verify your sender email is verified in SendGrid
- Check that SENDGRID_FROM_EMAIL matches the verified email
-
Check Logs
- Go to Vercel dashboard → Functions → View logs
- Look for error messages in the send-email function logs
- Check SendGrid dashboard → Activity for email send attempts
-
Check Spam Folder
- Emails might be landing in spam
- Add your sender email to contacts to improve deliverability
-
Check Console Errors
- Open browser developer console (F12)
- Look for network errors or JavaScript errors
- Verify the API endpoint is accessible
-
Verify Deployment
- Ensure the
/api/send-email.tsfile is deployed - Check Vercel functions tab to see if the function is listed
- Ensure the
- SendGrid free tier: 100 emails/day
- If exceeded, upgrade to a paid plan or wait 24 hours
- Monitor usage in SendGrid dashboard → Activity
-
Never Commit API Keys
- API keys should only be in Vercel environment variables
- Never commit them to the repository
- The
.env.examplefile shows required variables without actual values
-
Rate Limiting
- Consider adding rate limiting to prevent abuse
- Monitor SendGrid activity for unusual patterns
-
Input Validation
- The API endpoint validates email format
- HTML is escaped to prevent XSS attacks
- Consider adding CAPTCHA for additional protection
-
Create .env file
cp .env.example .env
-
Add your SendGrid credentials
SENDGRID_API_KEY=your_api_key_here SENDGRID_FROM_EMAIL=your_verified_email@example.com CONTACT_EMAIL=your_email@example.com -
Install Vercel CLI
npm install -g vercel
-
Run locally with Vercel dev
vercel dev
-
Test the form
- Open http://localhost:3000
- Fill out the contact form
- Check your email
For issues or questions:
- Check SendGrid documentation: https://docs.sendgrid.com
- Check Vercel documentation: https://vercel.com/docs
- Review the code in
/api/send-email.ts - Check GitHub Issues in this repository