Skip to main content

Send Email to All Members

curl -X POST https://api.sociapp.com/mail/send-all \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "subject": "Monthly Newsletter",
    "message": "<h1>Monthly Update</h1><p>Dear members, here is our monthly newsletter...</p>"
  }'
{
  "success": true,
  "message": "Email sent to all members successfully",
  "recipients": 156,
  "stats": {
    "total": 156,
    "sent": 156,
    "failed": 0
  }
}

Endpoint

POST /mail/send-all

Authentication

Requires JWT authentication token with admin role. Required Role: admin (only administrators can send to all members)

Request Body

subject
string
required
Email subject line for the mass email
message
string
required
Email message body. Supports HTML formatting.Example:
<h1>Important Announcement</h1>
<p>Dear members,</p>
<p>We are pleased to announce...</p>
<ul>
  <li>Point 1</li>
  <li>Point 2</li>
</ul>

Response Fields

success
boolean
Indicates whether the mass email operation was successful
message
string
Status message describing the result
recipients
number
Total number of members (socios) the email was sent to
stats
object
Detailed statistics about the email sending operation
stats.total
number
Total number of members in the database
stats.sent
number
Number of emails successfully sent
stats.failed
number
Number of emails that failed to send

Notes

  • Admin Only: Only users with the admin role can use this endpoint
  • Target Audience: Sends emails to all users marked as members (socios) in the database
  • HTML Support: The message body supports full HTML formatting
  • Batch Processing: Emails are sent in batches to avoid overwhelming the SMTP server
  • Error Handling: If some emails fail, the operation continues and reports statistics
  • Database Query: Recipients are fetched from the usuarios table where socio = 1
  • Performance: For large member lists, this operation may take some time to complete

Best Practices

  1. Test First: Send a test email using /mail/send before sending to all members
  2. HTML Validation: Ensure your HTML message is well-formed
  3. Subject Lines: Keep subject lines clear and concise (50-60 characters recommended)
  4. Timing: Consider sending mass emails during off-peak hours
  5. Content: Include unsubscribe information if required by local regulations

Build docs developers (and LLMs) love