JavaSript
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',
cc: [{ email: 'dinesh@bachmanity.com' }],
bcc: [{ email: 'jian@bachmanity.com' }],
}]
message.subject = 'Hello'
message.htmlBody = '<strong>it works!</strong>';
message.ippool = 'PiedPiper'
message.template = 'Welcome Mail'
const opts = {
emailMessage: message
};
try {
const data = await email.sendEmailWithTemplate(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');
$cc = new \sendpost\model\CopyTo();
$cc->setEmail('dinesh@bachmanity.com');
$to->setCc(array($cc));
$bcc = new \sendpost\model\CopyTo();
$bcc->setEmail('jian@bachmanity.com');
$to->setBcc(array($bcc));
$email_message->setTemplate('Welcome Mail');
$to = new \sendpost\model\To();
$to->setEmail('gavin@hooli.com');
$email_message->setTo(array($to));
$email_message->setFrom($from);
try {
$result = $apiInstance->sendEmailWithTemplate($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",
"cc": [{ "email": "dinesh@bachmanity.com" }],
"bcc": [{ "email": "jian@bachmanity.com" }],
}
],
"template": "Welcome Mail",
"subject": "Hello World",
"htmlBody": "<strong>it works!</strong>",
"ippool": "PiedPiper",
}
try:
api_response = api_instance.send_email_with_template(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)
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")
emailMessage.SetTemplate("Welcome Mail")
tos := make([]sendpost.To, 0)
to := &sendpost.To{}
to.SetEmail("gavin@hooli.com")
ccs := make([]sendpost.CopyTo, 0)
cc := &sendpost.CopyTo{}
cc.SetEmail("dinesh@bachmanity.com")
ccs = append(ccs, *cc)
to.SetCc(ccs)
bccs := make([]sendpost.CopyTo, 0)
bcc := &sendpost.CopyTo{}
bcc.SetEmail("jian@bachmanity.com")
bccs = append(bccs, *bcc)
to.SetBcc(bccs)
tos = append(tos, *to)
emailMessage.To = tos
emailRequest := sendpost.ApiSendEmailWithTemplateRequest{}
emailRequest = emailRequest.XSubAccountApiKey("your_api_key")
emailRequest = emailRequest.EmailMessage(emailMessage)
res, _, err := client.EmailApi.SendEmailWithTemplateExecute(emailRequest)
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',
cc: [{ email: 'dinesh@bachmanity.com' }],
bcc: [{ email: 'jian@bachmanity.com' }]
}]
email_message.subject = 'Hello World'
email_message.template = 'Welcome Mail'
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_with_template(x_sub_account_api_key, opts)
p result
rescue Sendpost::ApiError => e
puts "Exception when calling EmailApi->send_email: #{e}"
end
curl -X POST "https://api.sendpost.io/api/v1/subaccount/email/template" \
-H "accept: application/json" \
-H "X-SubAccount-ApiKey: your_api_key" \
-d '{
"from": { "email": "richard@piedpiper.com" },
"to": [{ "email": "gavin@hooli.com" }],
"templateId": "12345",
"dynamicData": {
"name": "Gavin",
"product": "Compression Algorithm"
},
"ippool": "PiedPiper"
}'
HttpResponse<String> response = Unirest.post("https://api.sendpost.io/api/v1/subaccount/email/template")
.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 \"template\": \"<string>\",\n \"templateId\": \"<string>\",\n \"templateVariables\": {}\n}")
.asString();[
{
"to": "<string>",
"submittedAt": 123,
"messageId": "<string>",
"errorCode": 123,
"message": "<string>"
}
]Email
Send Email With Template
Use this API to send an email with a predefined template. This makes it easy to integrate transactional emails with minimal code.
POST
/
subaccount
/
email
/
template
JavaSript
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',
cc: [{ email: 'dinesh@bachmanity.com' }],
bcc: [{ email: 'jian@bachmanity.com' }],
}]
message.subject = 'Hello'
message.htmlBody = '<strong>it works!</strong>';
message.ippool = 'PiedPiper'
message.template = 'Welcome Mail'
const opts = {
emailMessage: message
};
try {
const data = await email.sendEmailWithTemplate(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');
$cc = new \sendpost\model\CopyTo();
$cc->setEmail('dinesh@bachmanity.com');
$to->setCc(array($cc));
$bcc = new \sendpost\model\CopyTo();
$bcc->setEmail('jian@bachmanity.com');
$to->setBcc(array($bcc));
$email_message->setTemplate('Welcome Mail');
$to = new \sendpost\model\To();
$to->setEmail('gavin@hooli.com');
$email_message->setTo(array($to));
$email_message->setFrom($from);
try {
$result = $apiInstance->sendEmailWithTemplate($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",
"cc": [{ "email": "dinesh@bachmanity.com" }],
"bcc": [{ "email": "jian@bachmanity.com" }],
}
],
"template": "Welcome Mail",
"subject": "Hello World",
"htmlBody": "<strong>it works!</strong>",
"ippool": "PiedPiper",
}
try:
api_response = api_instance.send_email_with_template(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)
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")
emailMessage.SetTemplate("Welcome Mail")
tos := make([]sendpost.To, 0)
to := &sendpost.To{}
to.SetEmail("gavin@hooli.com")
ccs := make([]sendpost.CopyTo, 0)
cc := &sendpost.CopyTo{}
cc.SetEmail("dinesh@bachmanity.com")
ccs = append(ccs, *cc)
to.SetCc(ccs)
bccs := make([]sendpost.CopyTo, 0)
bcc := &sendpost.CopyTo{}
bcc.SetEmail("jian@bachmanity.com")
bccs = append(bccs, *bcc)
to.SetBcc(bccs)
tos = append(tos, *to)
emailMessage.To = tos
emailRequest := sendpost.ApiSendEmailWithTemplateRequest{}
emailRequest = emailRequest.XSubAccountApiKey("your_api_key")
emailRequest = emailRequest.EmailMessage(emailMessage)
res, _, err := client.EmailApi.SendEmailWithTemplateExecute(emailRequest)
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',
cc: [{ email: 'dinesh@bachmanity.com' }],
bcc: [{ email: 'jian@bachmanity.com' }]
}]
email_message.subject = 'Hello World'
email_message.template = 'Welcome Mail'
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_with_template(x_sub_account_api_key, opts)
p result
rescue Sendpost::ApiError => e
puts "Exception when calling EmailApi->send_email: #{e}"
end
curl -X POST "https://api.sendpost.io/api/v1/subaccount/email/template" \
-H "accept: application/json" \
-H "X-SubAccount-ApiKey: your_api_key" \
-d '{
"from": { "email": "richard@piedpiper.com" },
"to": [{ "email": "gavin@hooli.com" }],
"templateId": "12345",
"dynamicData": {
"name": "Gavin",
"product": "Compression Algorithm"
},
"ippool": "PiedPiper"
}'
HttpResponse<String> response = Unirest.post("https://api.sendpost.io/api/v1/subaccount/email/template")
.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 \"template\": \"<string>\",\n \"templateId\": \"<string>\",\n \"templateVariables\": {}\n}")
.asString();[
{
"to": "<string>",
"submittedAt": 123,
"messageId": "<string>",
"errorCode": 123,
"message": "<string>"
}
]Authorizations
This api key can be used only for sub account level operations
Body
application/json
Email message details with template information
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Template ID for the email template
Key-Value pair of template variables
Show child attributes
Show child attributes
Was this page helpful?
⌘I