Overview
The email API endpoint allows you to send formatted insurance quote emails to the configured recipient. The endpoint processes quote information and generates a professionally styled HTML email with client details, insurance type, and a WhatsApp contact link. This endpoint is used internally by the Seguros NAG application to notify the agency when a new quote request is submitted through the website.Endpoint Details
POST /api/enviar-email
Send a formatted insurance quote email
POSTPath:
/api/enviar-emailContent-Type:
application/json
Authentication & Configuration
This endpoint requires environment variables to be configured for nodemailer:Gmail account email address used to send emails
Gmail app password (not the regular password - must be an app-specific password)
The email service is configured to use Gmail. Ensure you have generated an app-specific password for your Gmail account.
Request Parameters
All parameters are sent in the JSON request body:The type of insurance being quoted (e.g., “Auto”, “Moto”, “Hogar”, “Bicicleta”)
Full name of the client requesting the quote
Phone number of the client. Will be formatted with Argentina’s country code (+54) for WhatsApp link generation
Email address of the client
Detailed information about the insurance request. Should be formatted with newline-separated key-value pairs (e.g., “Marca: Toyota\nModelo: Corolla\nAño: 2020”)
Response Format
Success Response
Indicates whether the email was sent successfully. Returns
true on success200
Error Response
Returns
false when an error occursError message describing what went wrong
500
Example Request
Example Response
Email Template Features
The generated email includes:- Branded Header: ESTUDIO NAG logo and branding
- Quote Reference Number: Randomly generated 4-digit reference number
- Client Information Section: Name, phone, and email displayed prominently
- Insurance Type Badge: Highlighted insurance type (Auto, Moto, etc.)
- Technical Specifications: Parsed details with key-value formatting
- WhatsApp Contact Link: Direct link with Argentina phone code (+54)
- Professional Styling: Dark theme with gradient backgrounds and responsive design
Error Handling
The endpoint handles errors gracefully and returns appropriate HTTP status codes:| Status Code | Description |
|---|---|
200 | Email sent successfully |
500 | Server error (nodemailer configuration issue, invalid request data, or network error) |
Implementation Details
The endpoint uses:- Nodemailer: SMTP client for sending emails via Gmail
- Next.js Route Handler: Server-side API route
- HTML Email Template: Inline CSS for email client compatibility
- WhatsApp Integration: Automatic phone number formatting and link generation
source/app/api/enviar-email/route.ts:4