GET
/
api
/
marketing
/
test-email-simple
Test Email Simple
curl --request GET \
  --url https://onlyautomator.com/api/marketing/test-email-simple
{
  "success": true,
  "message": "Test email successfully sent to your_email@example.com"
}

Send Marketing Email

Sends an email campaign via Resend. Allows targeting either a specific Resend audience ID or a dynamic list of users based on activity filters. Supports personalization and test mode.

Authentication

This endpoint requires a secret API key (MARKETING_API_SECRET environment variable) passed as a Bearer token in the Authorization header. This is not the standard user JWT token.

Request

Authorization
string
required
Bearer token containing the secret marketing API key. Format: Bearer YOUR_MARKETING_API_SECRET
subject
string
required
The subject line of the email.
content
string
required
The HTML content of the email. Supports personalization tags: {{first_name}}, {{last_name}}, {{full_name}}, {{email}}.
fromEmail
string
required
The email address to send from.
fromName
string
The name to display as the sender.
replyTo
string
The email address for replies (defaults to fromEmail).
audienceId
string
Option 1: The ID of the Resend audience to send the email to. If provided, user filters (filterActive, activeDays) are ignored.
filterActive
boolean
Option 2: If audienceId is not provided, set to true to filter users based on recent activity.
activeDays
number
Option 2: If filterActive is true, specifies the number of days to consider for recent activity (default: 30).
testMode
boolean
If true, only sends emails to the addresses specified in testEmails (useful for testing filters and content).
testEmails
array[string]
An array of email addresses to target when testMode is true.

Response

success
boolean
Indicates if the overall process was initiated successfully.
message
string
A summary message of the operation.
result
object
(Only when sending to audienceId) The direct response object from the Resend API.
total
number
(Only when sending to filtered users) Total number of users targeted.
successful
number
(Only when sending to filtered users) Number of emails sent successfully.
failed
number
(Only when sending to filtered users) Number of emails that failed to send.
errors
array
(Only when sending to filtered users) An array containing details of the first few send failures (if any).
test_mode
boolean
Indicates if the operation was run in test mode.

Error Codes

Status CodeDescription
400Missing required fields (subject, content, fromEmail) or invalid testEmails format.
401Invalid or missing marketing API key.
500Internal server error (e.g., fetching users failed, Resend API error).

Code Examples

// Send to a specific Resend Audience
const sendToAudience = async (audienceId, emailData, apiKey) => {
  const response = await fetch(`https://onlyautomator.com/api/marketing/send-email`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${apiKey}`
    },
    body: JSON.stringify({ ...emailData, audienceId })
  });
  return await response.json();
};

// Send to active users (last 30 days)
const sendToActiveUsers = async (emailData, apiKey) => {
  const response = await fetch(`https://onlyautomator.com/api/marketing/send-email`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${apiKey}`
    },
    body: JSON.stringify({ ...emailData, filterActive: true, activeDays: 30 })
  });
  return await response.json();
};

// Example Usage
const emailContent = {
  subject: "Special Offer Inside!",
  content: "<p>Hi {{first_name}}, check out our new products!</p>",
  fromEmail: "marketing@onlyautomator.com",
  fromName: "OnlyAutomator Team"
};
const marketingApiKey = process.env.MARKETING_API_SECRET; 

sendToAudience('resend_audience_id_123', emailContent, marketingApiKey)
  .then(result => console.log('Audience send result:', result))
  .catch(err => console.error(err));

sendToActiveUsers(emailContent, marketingApiKey)
  .then(result => console.log('Active users send result:', result))
  .catch(err => console.error(err));

Notes

  • Authorization: Uses a dedicated marketing API key, NOT user JWTs.
  • Targeting: Can target a Resend audience directly OR filter users from the database.
  • Batching: When sending to filtered users, emails are sent in batches of 50 to prevent timeouts.
  • Personalization: Supports {{first_name}}, {{last_name}}, {{full_name}}, {{email}} tags in the content.
  • Test Mode: Allows safe testing by targeting specific email addresses.

Query Parameters

email
string
required

The email address to send the test to

template
enum<string>
required

The template to use for the email

Available options:
login,
welcome,
setup,
feedback
firstName
string

The user's first name to insert in the template

Response

Email sent successfully

success
boolean
Example:

true

message
string
Example:

"Test email successfully sent to your_email@example.com"