Skip to main content

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
Method: POST
Path: /api/enviar-email
Content-Type: application/json

Authentication & Configuration

This endpoint requires environment variables to be configured for nodemailer:
EMAIL_USER
string
required
Gmail account email address used to send emails
EMAIL_PASS
string
required
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:
tipoSeguro
string
required
The type of insurance being quoted (e.g., “Auto”, “Moto”, “Hogar”, “Bicicleta”)
nombre
string
required
Full name of the client requesting the quote
telefono
string
required
Phone number of the client. Will be formatted with Argentina’s country code (+54) for WhatsApp link generation
email
string
required
Email address of the client
detalle
string
required
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

success
boolean
Indicates whether the email was sent successfully. Returns true on success
Status Code: 200
{
  "success": true
}

Error Response

success
boolean
Returns false when an error occurs
error
string
Error message describing what went wrong
Status Code: 500
{
  "success": false,
  "error": "Error al procesar la solicitud"
}

Example Request

curl -X POST https://your-domain.com/api/enviar-email \
  -H "Content-Type: application/json" \
  -d '{
    "tipoSeguro": "Auto",
    "nombre": "Juan Pérez",
    "telefono": "1145678901",
    "email": "[email protected]",
    "detalle": "Marca: Toyota\nModelo: Corolla\nAño: 2020\nVersion: XEI 2.0"
  }'

Example Response

{
  "success": true
}

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 CodeDescription
200Email sent successfully
500Server error (nodemailer configuration issue, invalid request data, or network error)
Common errors include:
  • Missing or invalid Gmail credentials in environment variables
  • Invalid email format in request body
  • Network issues preventing email delivery
  • Gmail security restrictions (ensure app passwords are enabled)

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
See the implementation at: source/app/api/enviar-email/route.ts:4

Build docs developers (and LLMs) love