Skip to main content
POST
/
subaccount
/
email
/
JavaScript
const { EmailApi, EmailMessage } = require('sendpost_js');
const email = new EmailApi();
const apiKey = 'your_api_key'; // {String} Sub-Account API Key

(async function() {
  const message = new EmailMessage();
  message.from = { email: 'richard@piedpiper.com' };
  message.to = [{ email: 'gavin@hooli.com' }]
  message.subject = 'Hello'
  message.htmlBody = '<strong>it works!</strong>';
  message.ippool = 'PiedPiper'

  const opts = {
    emailMessage: message
  };
  try {
    const data = await email.sendEmail(apiKey, opts)
    console.log('API called successfully. Returned data: ', data);
  } catch (error) {
    console.error(error);
  }
})()
require_once(__DIR__ . '/vendor/autoload.php');
$client = new GuzzleHttp\Client();

$apiInstance = new sendpost\api\EmailApi($client);

$x_sub_account_api_key = 'your_api_key'; // string | Sub-Account API Key
$email_message = new \sendpost\model\EmailMessage();
$email_message->setSubject('Hello World');
$email_message->setHtmlBody('<strong>it works!</strong>');
$email_message->setIppool('PiedPiper');
$from = new \sendpost\model\From();
$from->setEmail('richard@piedpiper.com');

$to = new \sendpost\model\To();
$to->setEmail('gavin@hooli.com');
$email_message->setTo(array($to));
$email_message->setFrom($from);

try {
$result = $apiInstance->sendEmail($x_sub_account_api_key, $email_message);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling EmailApi->sendEmail: ', $e->getMessage(), PHP_EOL;
}
import sendpost_python_sdk
from pprint import pprint
from sendpost_python_sdk.apis.tags import email_api

# Enter a context with an instance of the API client
with sendpost_python_sdk.ApiClient() as api_client:
# Create an instance of the API class
api_instance = email_api.EmailApi(api_client)
x_sub_account_api_key = "your_api_key" # str | Sub-Account API Key
email = {
"from": {
"email": "richard@piedpiper.com",
},
"to": [
{
"email": "gavin@hooli.com",
}
],
"subject": "Hello World",
"htmlBody": "<strong>it works!</strong>",
"ippool": "PiedPiper",
}
try:
api_response = api_instance.send_email(header_params={ 'X-SubAccount-ApiKey': x_sub_account_api_key}, body=email)
pprint(api_response)
except sendpost_python_sdk.ApiException as e:
print("Exception when calling EmailApi->send_email: %s\n" % e)
require 'sendpost_ruby_sdk'

api_instance = Sendpost::EmailApi.new
x_sub_account_api_key = 'your_api_key' # String | Sub-Account API Key
email_message = Sendpost::EmailMessage.new
email_message.from = {
email: 'richard@piedpiper.com'
}
email_message.to = [{
email: 'gavin@hooli.com'
}]
email_message.subject = 'Hello World'
email_message.html_body = '<strong>it works!</strong>'
email_message.ippool = 'PiedPiper'

opts = {
email_message: email_message # EmailMessage | Email message
}

begin
result = api_instance.send_email(x_sub_account_api_key, opts)
p result
rescue Sendpost::ApiError => e
puts "Exception when calling EmailApi->send_email: #{e}"
end
cfg := sendpost.NewConfiguration()
client := sendpost.NewAPIClient(cfg)

emailMessage := sendpost.EmailMessage{}
emailMessage.SetSubject("Hello World")
emailMessage.SetHtmlBody("<strong>it works!</strong>")
emailMessage.SetIppool("PiedPiper")
emailMessage.From = &sendpost.From{}
emailMessage.From.SetEmail("richard@piedpiper.com")
tos := make([]sendpost.To, 0)
to := &sendpost.To{}
to.SetEmail("gavin@hooli.com")
tos = append(tos, *to)
emailMessage.To = tos

emailRequest := sendpost.ApiSendEmailRequest{}
emailRequest = emailRequest.XSubAccountApiKey("your_api_key")
emailRequest = emailRequest.EmailMessage(emailMessage)
res, _, err := client.EmailApi.SendEmailExecute(emailRequest)
curl -X POST "https://api.sendpost.io/api/v1/subaccount/email/" \
-H "accept: application/json" \
-H "X-SubAccount-ApiKey: your_api_key" \
-d '{
"from": { "email": "richard@piedpiper.com" },
"to": [{ "email": "gavin@hooli.com" }],
"subject": "Hello World",
"htmlBody": "<strong>it works!</strong>",
"ippool": "PiedPiper"
}'
HttpResponse<String> response = Unirest.post("https://api.sendpost.io/api/v1/subaccount/email/")
.header("X-SubAccount-ApiKey", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"from\": {\n \"email\": \"<string>\",\n \"name\": \"<string>\"\n },\n \"replyTo\": {\n \"email\": \"<string>\",\n \"name\": \"<string>\"\n },\n \"to\": [\n {\n \"email\": \"<string>\",\n \"name\": \"<string>\",\n \"cc\": [\n {\n \"email\": \"<string>\",\n \"name\": \"<string>\",\n \"customFields\": {}\n }\n ],\n \"bcc\": [\n {\n \"email\": \"<string>\",\n \"name\": \"<string>\",\n \"customFields\": {}\n }\n ],\n \"customFields\": {}\n }\n ],\n \"subject\": \"<string>\",\n \"preText\": \"<string>\",\n \"htmlBody\": \"<string>\",\n \"textBody\": \"<string>\",\n \"ampBody\": \"<string>\",\n \"ippool\": \"<string>\",\n \"headers\": {},\n \"trackOpens\": true,\n \"trackClicks\": true,\n \"groups\": [\n \"<string>\"\n ],\n \"attachments\": [\n {\n \"content\": \"<string>\",\n \"filename\": \"<string>\"\n }\n ],\n \"webhookEndpoint\": \"<string>\"\n}")
.asString();
[
  {
    "to": "<string>",
    "submittedAt": 123,
    "messageId": "<string>",
    "errorCode": 123,
    "message": "<string>"
  }
]

Authorizations

X-SubAccount-ApiKey
string
header
required

This api key can be used only for sub account level operations

Body

application/json

Email message details

from
object
replyTo
object
to
object[]
subject
string
preText
string
htmlBody
string
textBody
string
ampBody
string
ippool
string
headers
object
trackOpens
boolean
trackClicks
boolean
groups
string[]
attachments
object[]
webhookEndpoint
string

Response

200 - application/json

A list of email message response objects.

to
string
submittedAt
integer<int64>

UNIX epoch nano timestamp

messageId
string

Message UUID

errorCode
integer
message
string