Skip to main content
Once your Mailgun provider and IP Pool are configured, you can send emails through Mailgun using the standard SendPost API.
Important: You must include the ippool parameter in your API request to route emails through Mailgun.

Basic Email Example

curl -X POST "https://api.sendpost.io/api/v1/subaccount/email/" \
  -H "X-SubAccount-ApiKey: YOUR_SENDPOST_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "from": {
      "email": "[email protected]",
      "name": "Your Name"
    },
    "to": [{
      "email": "[email protected]",
      "name": "Recipient Name"
    }],
    "subject": "Hello from SendPost via Mailgun",
    "htmlBody": "<h1>Hello!</h1><p>This email is sent through Mailgun.</p>",
    "textBody": "Hello! This email is sent through Mailgun.",
    "ippool": "mailgun-pool",
    "trackOpens": true,
    "trackClicks": true
  }'

Email with Personalization

curl -X POST "https://api.sendpost.io/api/v1/subaccount/email/" \
  -H "X-SubAccount-ApiKey: YOUR_SENDPOST_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "from": {
      "email": "[email protected]",
      "name": "Your Company"
    },
    "to": [{
      "email": "[email protected]",
      "name": "John Doe",
      "customFields": {
        "firstName": "John",
        "accountType": "Premium"
      }
    }],
    "subject": "Welcome {{firstName}}!",
    "htmlBody": "<h1>Welcome {{firstName}}!</h1><p>Your {{accountType}} account is ready.</p>",
    "ippool": "mailgun-pool",
    "trackOpens": true,
    "trackClicks": true
  }'

Using Mailgun IP Pools

If you have IP Pools configured in your Mailgun account, you can specify which Mailgun IP Pool to use via the tpspIppool parameter.
The tpspIppool field is optional. Use it when you want to route emails through a specific IP Pool on the Mailgun side, separate from the SendPost IP Pool routing.
Parameters:
  • ippool: The SendPost IP Pool that routes traffic to Mailgun (required)
  • tpspIppool: The IP Pool name configured in your Mailgun account (optional)
curl -X POST "https://api.sendpost.io/api/v1/subaccount/email/" \
  -H "X-SubAccount-ApiKey: YOUR_SENDPOST_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "from": {
      "email": "[email protected]",
      "name": "Your Company"
    },
    "to": [{
      "email": "[email protected]",
      "name": "Recipient Name"
    }],
    "subject": "Hello from SendPost via Mailgun",
    "htmlBody": "<h1>Hello!</h1><p>This email is sent through a specific Mailgun IP Pool.</p>",
    "ippool": "mailgun-pool",
    "tpspIppool": "transactional",
    "trackOpens": true,
    "trackClicks": true
  }'

Using a Specific Mailgun IP Address

If you have dedicated IPs in your Mailgun account, you can specify a specific IP address to use for sending via the tpspIp parameter.
The IP address specified must be owned by your Mailgun account. This is different from IP pools which allow Mailgun to select an IP from a pool.
Parameters:
  • ippool: The SendPost IP Pool that routes traffic to Mailgun (required)
  • tpspIp: The specific IP address owned by your Mailgun account (optional)
curl -X POST "https://api.sendpost.io/api/v1/subaccount/email/" \
  -H "X-SubAccount-ApiKey: YOUR_SENDPOST_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "from": {
      "email": "[email protected]",
      "name": "Your Company"
    },
    "to": [{
      "email": "[email protected]",
      "name": "Recipient Name"
    }],
    "subject": "Hello from SendPost via Mailgun",
    "htmlBody": "<h1>Hello!</h1><p>This email is sent from a specific IP.</p>",
    "ippool": "mailgun-pool",
    "tpspIp": "192.0.2.1",
    "trackOpens": true,
    "trackClicks": true
  }'

Response

Success Response (HTTP 200):
[
  {
    "messageId": "abc123-def456-ghi789",
    "errorCode": 0,
    "to": "[email protected]"
  }
]

Next Steps