Skip to content

Send Email to All Contacts

Send email messages to all available contacts in your database. The operation is asynchronous: the API records every message in persistence, schedules delivery in BullMQ, and returns an enqueue summary.

  • Include the bearer token in Authorization: Bearer <token>.
  • Only members that accepted the current terms can trigger messaging actions; otherwise the service returns 403 Forbidden.
interface EmailAllMessagePayload extends EmailMessageBasePayload {}
interface EmailMessageBasePayload {
subject: string;
message: string; // HTML or plain text supported by the provider
}
FieldTypeRequiredDescription
subjectstringYesEmail subject
messagestringYesEmail content (HTML or plain text)
{
"subject": "SendMe Newsletter - Important Updates",
"message": "<h1>Hello Everyone!</h1><p>We want to share some important updates about our services...</p><p>Thank you for being part of our community.</p>"
}

The API responds with the shared MessageEnqueueResultDto contract:

interface MessageEnqueueResultDto {
queueId: string; // BullMQ job identifier, empty when nothing was enqueued
channel: 'email';
messages: Array<{
id: string; // UUID of the persisted message
recipient: string; // Email address normalized by the backend
}>;
}
{
"queueId": "email-queue-67890",
"channel": "email",
"messages": [
{
"id": "msg-uuid-1",
"recipient": "[email protected]"
},
{
"id": "msg-uuid-2",
"recipient": "[email protected]"
},
{
"id": "msg-uuid-3",
"recipient": "[email protected]"
}
]
}

When there are no contacts with valid emails in the database, the service responds with 200 OK, an empty queueId, and an empty messages array.

{
"queueId": "",
"channel": "email",
"messages": []
}
async function sendEmailToAll(token: string, payload: EmailAllMessagePayload) {
const response = await fetch('/api/messages/email/all', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
body: JSON.stringify(payload),
});
if (!response.ok) {
throw new Error(`Email broadcast failed: ${response.status}`);
}
const data: MessageEnqueueResultDto = await response.json();
return data;
}
// Monthly newsletter
const result = await sendEmailToAll('your-token', {
subject: 'SendMe Newsletter - March 2024',
message: `
<div style="max-width: 600px; margin: 0 auto; font-family: Arial, sans-serif;">
<header style="background: #007cba; color: white; padding: 20px; text-align: center;">
<h1>March Newsletter</h1>
</header>
<main style="padding: 20px;">
<h2>What's New This Month</h2>
<p>This month we've added new features that will improve your experience...</p>
<h3>New Features:</h3>
<ul>
<li>Enhanced message editor</li>
<li>Advanced delivery reports</li>
<li>Integration with new providers</li>
</ul>
</main>
<footer style="background: #f8f9fa; padding: 15px; text-align: center; color: #666;">
<p>If you don't want to receive these emails, <a href="#">click here</a></p>
</footer>
</div>
`
});
console.log(`Newsletter sent to ${result.messages.length} contacts`);
const wellCraftedEmail = {
subject: "Your Monthly Activity Summary - SendMe",
message: `
<div style="max-width: 600px; margin: 0 auto;">
<h2>Hello {{name}},</h2>
<p>Here's your monthly activity summary...</p>
<!-- Relevant and valuable content -->
</div>
`
};
  • Always include an unsubscribe option
  • Respect local and international regulations (CAN-SPAM, GDPR)
  • Maintain a clear privacy policy
// Consider sending when users are most active
// For example: Tuesday to Thursday, 10:00 AM - 2:00 PM
  • The backend removes duplicated recipients per batch and silently skips invalid destinations.
  • Balance validation runs before queuing; insufficient credits return an error response without enqueuing messages.
  • Use the returned queueId to correlate delivery status inside the admin UI or via dedicated status endpoints.
  • Each message persists provider metadata and can be audited through the messaging module filters.
  • Important: Consider carefully the impact of sending to all contacts, especially for cost, content relevance, and email marketing regulation compliance.