This document explains how to set up and use the SendGrid email integration for the MTA Data Assistant.
Add your SendGrid API key to your environment variables:
# .env.local
SENDGRID_API_KEY=your_sendgrid_api_key_hereThe following DNS records have been added to your mta-data.com domain:
- CNAME
url622.mta-data.com→sendgrid.net - CNAME
56285903.mta-data.com→sendgrid.net - CNAME
em3637.mta-data.com→u56285903.wl154.sendgrid.net - CNAME
s1._domainkey.mta-data.com→s1.domainkey.u56285903.wl154.sendgrid.net - CNAME
s2._domainkey.mta-data.com→s2.domainkey.u56285903.wl154.sendgrid.net - TXT
_dmarc.mta-data.com→v=DMARC1; p=none;
- Email Button: Click the email icon on any AI response to send it via email
- Email Modal: Enter recipient email address and send formatted emails
- Professional Templates: Beautiful HTML emails with MTA branding
- Direct Email Tool: The AI can send emails directly using the
sendEmailtool - Natural Language: Users can ask "Email this analysis to john@example.com"
# Send a test email
curl -X POST http://localhost:3000/api/email/test \
-H "Content-Type: application/json" \
-d '{"to": "your-email@example.com"}'- Start your development server:
npm run dev - Go to the chat interface
- Ask a question and get a response
- Click the email icon (📧) on the response
- Enter an email address and send
- HTML Formatting: Professional email templates with MTA branding
- Conversation Links: Links to continue conversations in the web interface
- Mobile Responsive: Emails look great on all devices
- Authentication: Emails are sent from your verified
mta-data.comdomain - Reply-To: Recipients can reply to the sender
POST /api/email/chat- Send chat response via emailPOST /api/email/test- Send test email
- "Invalid API Key": Check that
SENDGRID_API_KEYis set correctly - "Sender not verified": Ensure your domain is verified in SendGrid
- "Email not received": Check spam folder, verify recipient email
- Check environment variables:
console.log(process.env.SENDGRID_API_KEY) - Test with the test endpoint:
/api/email/test - Check SendGrid dashboard for delivery status
- Verify DNS records are propagated
// User clicks email button → modal opens → enters email → sends// User: "Email this analysis to john@example.com"
// AI: Uses sendEmail tool to send the responseconst response = await fetch('/api/email/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
to: 'recipient@example.com',
messageContent: 'AI response content',
conversationId: 'conv-123'
})
});- API key is server-side only (not exposed to client)
- Email validation prevents injection attacks
- Rate limiting should be implemented for production
- Consider implementing user authentication for email features
- Test the integration with the test endpoint
- Verify emails are received and formatted correctly
- Test the UI email functionality
- Consider adding email templates for different types of responses
- Implement rate limiting for production use