Prerequisites
- A SparkPost account
- A SparkPost API key with Transmissions: Read/Write permissions
Setup
1
Create a SparkPost API key
In SparkPost, open API keys and create a key with Transmissions permission.
2
Configure in Courier
Open the in Courier, enter your API key and From Address, then save.
Overrides
covers the two levels and which one wins. lists the fields every email provider takes. A provider override changes what Courier sends to SparkPost’s Transmissions API. For example, add an attachment:const { requestId } = await courier.send.message({
message: {
template: "nt_01kx4h2jdafq8bk9aftxak4b40",
to: {
email: "sarah@acme-corp.com",
},
providers: {
sparkpost: {
override: {
body: {
content: {
attachments: [
{
name: "billing.pdf",
type: "application/pdf",
data: "Q29uZ3JhdHVsYXRpb25zLCB5b3UgY2FuIGJhc2U2NCBkZWNvZGUh",
},
],
},
},
},
},
},
},
});
response = client.send.message(
message={
"template": "nt_01kx4h2jdafq8bk9aftxak4b40",
"to": {
"email": "sarah@acme-corp.com",
},
"providers": {
"sparkpost": {
"override": {
"body": {
"content": {
"attachments": [
{
"name": "billing.pdf",
"type": "application/pdf",
"data": "Q29uZ3JhdHVsYXRpb25zLCB5b3UgY2FuIGJhc2U2NCBkZWNvZGUh",
},
],
},
},
},
},
},
},
)
curl -X POST https://api.courier.com/send \
-H "Authorization: Bearer $COURIER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"message": {
"template": "nt_01kx4h2jdafq8bk9aftxak4b40",
"to": {
"email": "sarah@acme-corp.com"
},
"providers": {
"sparkpost": {
"override": {
"body": {
"content": {
"attachments": [
{
"name": "billing.pdf",
"type": "application/pdf",
"data": "Q29uZ3JhdHVsYXRpb25zLCB5b3UgY2FuIGJhc2U2NCBkZWNvZGUh"
}
]
}
}
}
}
}
}
}'
response = courier.send_.message(
message: {
template: "nt_01kx4h2jdafq8bk9aftxak4b40",
to: {
email: "sarah@acme-corp.com"
},
providers: {
sparkpost: {
override: {
body: {
content: {
attachments: [
{
name: "billing.pdf",
type: "application/pdf",
data: "Q29uZ3JhdHVsYXRpb25zLCB5b3UgY2FuIGJhc2U2NCBkZWNvZGUh"
}
]
}
}
}
}
}
}
)
response, err := client.Send.Message(context.TODO(), courier.SendMessageParams{
Message: courier.SendMessageParamsMessage{
To: courier.SendMessageParamsMessageToUnion{
OfUserRecipient: &shared.UserRecipientParam{
Email: courier.String("sarah@acme-corp.com"),
},
},
Template: courier.String("nt_01kx4h2jdafq8bk9aftxak4b40"),
Providers: shared.MessageProvidersParam{
"sparkpost": shared.MessageProvidersTypeParam{
Override: map[string]any{
"body": map[string]any{
"content": map[string]any{
"attachments": []any{
map[string]any{
"name": "billing.pdf",
"type": "application/pdf",
"data": "Q29uZ3JhdHVsYXRpb25zLCB5b3UgY2FuIGJhc2U2NCBkZWNvZGUh",
},
},
},
},
},
},
},
},
})
SendMessageParams params = SendMessageParams.builder()
.message(SendMessageParams.Message.builder()
.to(UserRecipient.builder().email("sarah@acme-corp.com").build())
.template("nt_01kx4h2jdafq8bk9aftxak4b40")
.providers(MessageProviders.builder()
.putAdditionalProperty("sparkpost", JsonValue.from(java.util.Map.of("override", java.util.Map.of(
"body", java.util.Map.of(
"content", java.util.Map.of(
"attachments", java.util.List.of(
java.util.Map.of(
"name", "billing.pdf",
"type", "application/pdf",
"data", "Q29uZ3JhdHVsYXRpb25zLCB5b3UgY2FuIGJhc2U2NCBkZWNvZGUh"
)
)
)
)
))))
.build())
.build())
.build();
SendMessageResponse response = client.send().message(params);
$response = $client->send->message(
message: [
'template' => 'nt_01kx4h2jdafq8bk9aftxak4b40',
'to' => [
'email' => 'sarah@acme-corp.com',
],
'providers' => [
'sparkpost' => [
'override' => [
'body' => [
'content' => [
'attachments' => [
[
'name' => 'billing.pdf',
'type' => 'application/pdf',
'data' => 'Q29uZ3JhdHVsYXRpb25zLCB5b3UgY2FuIGJhc2U2NCBkZWNvZGUh',
],
],
],
],
],
],
],
],
);
SendMessageParams parameters = new()
{
Message = new()
{
To = new UserRecipient { Email = "sarah@acme-corp.com" },
Template = "nt_01kx4h2jdafq8bk9aftxak4b40",
Providers = new Dictionary<string, MessageProvidersType>()
{
{
"sparkpost",
new()
{
Override = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(
"""
{
"body": {
"content": {
"attachments": [
{
"name": "billing.pdf",
"type": "application/pdf",
"data": "Q29uZ3JhdHVsYXRpb25zLCB5b3UgY2FuIGJhc2U2NCBkZWNvZGUh"
}
]
}
}
}
"""
),
}
},
},
},
};
var response = await client.Send.Message(parameters);
courier send message \
--api-key "$COURIER_API_KEY" \
--message.to '{"email": "sarah@acme-corp.com"}' \
--message.template nt_01kx4h2jdafq8bk9aftxak4b40 \
--message.providers '{"sparkpost": {"override": {"body": {"content": {"attachments": [{"name": "billing.pdf", "type": "application/pdf", "data": "Q29uZ3JhdHVsYXRpb25zLCB5b3UgY2FuIGJhc2U2NCBkZWNvZGUh"}]}}}}}'
With Courier MCP, send my template to sarah@acme-corp.com with an attachment through SparkPost.
Provider details
sparkpost
routing.channels instead is supported, and sends through just this provider.
Send to a specific provider
When that is worth doing, and what you give up: failover, channel priority, and providers you add later.