Overview
The Send Email API endpoint processes contact form submissions and sends emails via SMTP. It includes reCAPTCHA verification to prevent spam and automated submissions.Endpoint
Authentication
This endpoint uses Google reCAPTCHA v2 for bot protection. A valid captcha token must be included in every request.Request Parameters
First name of the contact form submitter.
Last name of the contact form submitter. Optional but included in email subject.
Email address of the submitter. Used as the
replyTo address in the outgoing email.Phone number of the submitter. Optional field, numeric only.
The message body from the contact form.
The reCAPTCHA token obtained from the frontend after user verification.
SMTP Configuration
The endpoint uses Nodemailer with the following SMTP settings:- Host:
mail.plugin.uy - Port:
465 - Secure:
true(SSL/TLS) - Authentication: Uses
EMAIL_USERandEMAIL_PASSenvironment variables
Email Recipients
Recipients are configured via theEMAIL_TO environment variable. Multiple recipients can be specified as a comma-separated list:
If
EMAIL_TO is not set, emails default to: [email protected] and [email protected]Response
Success Response
Success confirmation message.
Error Responses
Error message describing what went wrong.
400 Bad Request - Missing Fields
nombre, email, message, or captchaToken are missing.
400 Bad Request - Invalid Captcha
405 Method Not Allowed
500 Internal Server Error - Captcha Verification
500 Internal Server Error - Email Sending
Example Request
Example Success Response
200 OK
Example Error Response
400 Bad Request
Email Format
The sent email includes both plain text and HTML versions:Subject Line
Email Headers
- From:
"Plugin Contacto" <{EMAIL_USER}> - Reply-To:
{email}(submitter’s email) - To: Recipients from
EMAIL_TOenvironment variable
Email Body
The HTML email includes:- Sender’s full name
- Email address
- Phone number (if provided)
- Message content
The
replyTo header is set to the submitter’s email, allowing direct replies from your email client.Environment Variables
Required environment variables:| Variable | Description | Required |
|---|---|---|
RECAPTCHA_SECRET_KEY | Google reCAPTCHA v2 secret key | Yes |
EMAIL_USER | SMTP authentication username | Yes |
EMAIL_PASS | SMTP authentication password | Yes |
EMAIL_TO | Comma-separated list of recipient emails | No (defaults exist) |
Error Handling
The endpoint implements comprehensive error handling:- Validation Errors: Checks for required fields before processing
- Captcha Verification: Validates token with Google’s API
- SMTP Errors: Catches and logs email sending failures
- Method Validation: Only accepts POST requests
Security Considerations
- reCAPTCHA v2 prevents automated bot submissions
- SMTP authentication uses secure SSL/TLS (port 465)
- Email addresses are validated on the frontend before submission
- The authenticated email user is always used as the sender to prevent spoofing
- User’s email is set as
replyTo, notfrom, for security
Related
- reCAPTCHA Integration - Learn how to integrate reCAPTCHA on the frontend