Send Email over API
You can use the Email API (opens in a new tab) as another way of sending emails to your customers.
Prerequisites
To send an email with Infobip, your domain needs to be active in the Infobip system. Verify your email domain on the User Profile in your Infobip account (opens in a new tab).
Fully-featured Email
To send a fully-featured email - send one or more email messages with attachments to one or more destination addresses. For more details, see Send a Fully Featured Email (opens in a new tab) reference documentation.
Send Email to Multiple Recipients
Send the same email to multiple recipient addresses by including more than one to
parameters in the request.
Send an Email With Multiple Attachments
To send an email with more than one attachment, add multiple attachment parameters in the request.
Send Email to Multiple To, Cc, Bcc Recipients
Send the same email to multiple recipient addresses by including more than one to
, cc
, bcc
parameters in the request.
curl -s --user user:password \
https://./3/send \
-F from='Jane Smith ' \
-F to='john.smith@somedomain.com' \
-F to='jane.smith@somedomain.com' \
-F cc='juliet.smith@somedomain.com' \
-F cc='abram.smith@somedomain.com' \
-F bcc='joy.smith@somedomain.com' \
-F bcc='clare.smith@somedomain.com' \
-F subject='Mail subject text' \
-F text='Mail body text' \
--form-string html='Html bodyRich HTML message body.' \
-F attachment=@files/image1.jpg
Send personalized emails using templates
Send personalized emails by adding placeholder values within the to
parameter of the request. If you want to send the message based on a previously defined template, pass the template identifier value in the templateId
parameter. To manage Templates, login (opens in a new tab) to the Infobip web interface.
Send an email with custom messageID
Send emails with custom messageId
by including your unique messageId
within the to
parameter of the request.
Send emails with dynamic content
To send email with dynamic content, use the Template language within your HTML content and define the placeholder values in the to
parameter of the request. Add any of the available Template language constructs in the HTML content to solve substitutions, conditional statements, or iterations.
To use the new Template language constructs in an API request, provide the parameter templateLanguageVersion=2.
If you prefer to use the old handlebar {{helpers}} in your HTML, do not specify the TemplateLanguageVersion parameter in the API request. The following table shows examples for the handlebar {{helpers}}.
See the Send Fully Featured Email (opens in a new tab) reference documentation.
Handlebar helper examples
HTML REQUEST | TO JSON REQUEST | RESOLVED HTML |
---|---|---|
Helper Example: #eq | ||
{{#eq name "Bob"}} Dear {{name}} {{else}} Hi {{name}} {{/eq}} | { "to": "john.smith@somedomain.com", "placeholders": { "name": "Bob" } } | Dear Bob |
Helper Example: #each | ||
{{#each friends}} Hi {{this}} {{/each}} | { "to": "john.smith@somedomain.com", "placeholders": { "friends":["Bob","John","Jack"] } } | Hi Bob Hi John Hi Jack |
Helper Example: #unlessEq | ||
{{#unlessEq name "Bob"}} Dear {{name}} {{else}} Hi {{name}} {{/unlessEq}} | { "to": "john.smith@somedomain.com", "placeholders": { "name": "Bob" } } | Hi Bob |
Helper Example: #default | ||
Hi {{name}} | { "to": "john.smith@somedomain.com", "placeholders": { "name": "Bob" } } | Hi Bob |
Helper Example: #gt | ||
{{#gt age 12}} Welcome {{name}}! {{else}} Hey {{name}}, you are under age {{/gt}} | { "to": "john.smith@somedomain.com", "placeholders": { "name": "Bob" , "age":10 } } | Hey Bob, you are under age |
Helper Example: #lt | ||
{{#lt age 12}} Welcome {{name}}! {{else}} Sorry {{name}}, This is kids arena {{/lt}} | { "to": "john.smith@somedomain.com", "placeholders": { "name": "Bob" , "age":10 } } | Welcome Bob! |
Helper Example: #equalsIgnoreCase | ||
{{#equalsIgnoreCase gender "male"}} Dear Mr {{name}} {{else}} Dear customer {{/equalsIgnoreCase}} | { "to": "john.smith@somedomain.com", "placeholders":{ "name": "Bob" , "gender": "MALE" } } | Dear Mr Bob |
Helper Example: #gte | ||
{{#gte age 12}} Welcome {{name}}! {{else}} Hey {{name}}, you are under age {{/gte}} | { "to": "john.smith@somedomain.com", "placeholders": { "name": "Bob" , "age":10 } } | Hey Bob, you are under age |
Helper Example: #lte | ||
{{#lte age 12}} Welcome {{name}}! {{else}} Sorry {{name}}, This is kids arena {{/lte}} | { "to": "john.smith@somedomain.com", "placeholders": { "name": "Bob" , "age":10 } } | Welcome Bob! |
Helper Example: #compare | ||
{{#compare name "!=" "Bob"}}Hi {{name}}{{else}} Dear Bob{{/compare}} | { "to": "john.smith@somedomain.com", "placeholders": { "name": "Jane" , "age":10 } } | Hi Jane |
Helper Example: #equals | ||
{{#equals name "Bob"}} Dear {{name}} {{else}} Hi {{name}} {{/equals}} | { "to": "john.smith@somedomain.com", "placeholders": { "name": "Bob" } } | Dear Bob |
Helper Example: #lessThan | ||
{{#lessThan age 12}} Welcome {{name}}! {{else}} Sorry {{name}}, This is kids arena {{/lessThan}} | { "to": "john.smith@somedomain.com", "placeholders": { "name": "Bob" , "age":10 } } | Welcome Bob! |
Helper Example: #lessThanOrEquals | ||
{{#lessThanOrEquals age 12}} Welcome {{name}}! {{else}} Sorry {{name}}, This is kids arena {{/lte}} | { "to": "john.smith@somedomain.com", "placeholders": { "name": "Bob" , "age":10 } } | Welcome Bob! |
Helper Example: #greaterThan | ||
{{#greaterThan age 12}} Welcome {{name}}! {{else}} Hey {{name}}, you are under age {{/greaterThan }} | { "to": "john.smith@somedomain.com", "placeholders": { "name": "Bob" , "age":10 } } | Hey Bob, you are under age |
Helper Example: #greaterThanOrEquals | ||
{{#greaterThanOrEquals age 12}} Welcome {{name}}! {{else}} Hey {{name}}, you are under age{{/greaterThanOrEquals }} | { "to": "john.smith@somedomain.com", "placeholders": { "name": "Bob" , "age":10 } } | Hey Bob, you are under age |
Helper Example: #when | ||
{{#when name "!=" "Bob"}} Hi {{name}}{{else}}Dear Bob{{/when}} | { "to": "john.smith@somedomain.com", "placeholders": { "name": "Jane" , "age":10 } } | Hey Jane |
Helper Example: #contains | ||
{{#contains friends "Bob"}} Hi {{this}} {{/each}} | { "to": "john.smith@somedomain.com", "placeholders": { "friends":["Bob","John","Jack"] } } | Hi Bob |
Helper Example: #and | ||
{{#and great magnificent}}Bob{{else}}Jane{{/and}} | { "to": "john.smith@somedomain.com", "placeholders": { "great": true, "magnificent": true } } | Hi Bob |
Helper Example: #formatNumber | ||
{{#formatNumber price}} {{/formatNumber}} | { "to": "john.smith@somedomain.com", "placeholders": { "price":10000 } } | 10,000 |
Helper Example: #isTruthy | ||
{{#isTruthy Male}}Hi Bob{{else}}Hi Jane{{/isTruthy}} | { "to": "john.smith@somedomain.com", "placeholders": { "Male": true } } | Hi Bob |
Helper Example: #isFalsey | ||
{{#isFalsey Male}}Hi Bob{{else}}Hi Jane{{/isFalsey}} | { "to": "john.smith@somedomain.com", "placeholders": { "Male": true } } | Hi Jane |
Helper Example: #ifEven | ||
{{#ifEven age}}Hi Bob{{else}}Hi Jane{{/ifEven}} | { "to": "john.smith@somedomain.com", "placeholders": { "age": 20 } } | Hi Bob |
Helper Example: #ifOdd | ||
{{#ifOdd age}}Hi Bob{{else}}Hi Jane{{/ifOdd}} | { "to": "john.smith@somedomain.com", "placeholders": { "age": 20 } } | Hi Jane |
Helper Example: #ifNth | ||
{{#ifNth age balance}}Hi Bob{{else}}Hi Jane{{/ifNth}} | { "to": "john.smith@somedomain.com", "placeholders": { "age": 20, "balance": 20000 } } | Hi Bob |
Helper Example: #is | ||
{{#is name "Bob"}}Dear {{name}}{{else}}Hi {{name}}{{/is}} | { "to": "john.smith@somedomain.com", "placeholders": { "name": "Bob" , "age":10 } } | Dear Bob |
Helper Example: #isnt | ||
{{#isnt name "Bob"}}Dear {{name}}{{else}}Hi {{name}}{{/isnt}} | { "to": "john.smith@somedomain.com", "placeholders": { "name": "Bob" , "age":10 } } | Hi Bob |
Helper Example: #neither | ||
{{#neither great magnificent}}A{{else}}B{{/neither}} | { "to": "john.smith@somedomain.com", "placeholders": { great: true, magnificent: false } } | B |
Helper Example: #not | ||
{{#not great}}A {{else}} B{{/not}} | { "to": "john.smith@somedomain.com", "placeholders": { great: true, magnificent: false } } | B |
Helper Example: #or | ||
{{#or great magnificent}}A{{else}}B{{/or}} | { "to": "john.smith@somedomain.com", "placeholders": { great: true, magnificent: false } } | A |
Helper Example: #unlessGt | ||
{{#unlessGt physics chemistry}}Hi {{name}}your score in Physics :{{physics}}{{else}}Hi {{name}}your score in Chemistry : {{chemistry}}{{/unlessGt}} | { "to": "john.smith@somedomain.com", "placeholders": { "name": "Bob" , "physics": 70 , "chemistry": 75 } } | Hi Bob your score in Physics : 70 |
Helper Example: #unlessLt | ||
{{#unlessLt physics chemistry}}Hi {{name}}your score in Physics : {{physics}}{{else}}Hi {{name}}your score in Chemistry : {{chemistry}}{{/unlessLt}} | { "to": "john.smith@somedomain.com", "placeholders": { "name": "Bob" , "physics": 70 , "chemistry": 75 } } | Hi Bob your score in Chemistry : 75 |
Helper Example: #unlessGteq | ||
{{#unlessGteq physics chemistry}}Hi {{name}}your score in Physics : {{physics}}{{else}}Hi {{name}}your score in Chemistry : {{chemistry}}{{/unlessGteq}} | { "to": "john.smith@somedomain.com", "placeholders": { "name": "Bob" , "physics": 70 , "chemistry": 75 } } | Hi Bob your score in Physics : 70 |
Helper Example: #unlessLteq | ||
{{#unlessLteq physics chemistry}}Hi {{name}}your score in Physics : {{physics}}{{else}}Hi {{name}}your score in Chemistry : {{chemistry}}{{/unlessLteq}} | { "to": "john.smith@somedomain.com", "placeholders": { "name": "Bob" , "physics": 70 , "chemistry": 75 } } | Hi Bob your score in Chemistry : 75 |
Email delivery reports
The Email delivery reports (opens in a new tab) method allows you to get one-time delivery reports (DLR) for all sent emails. Email delivery reports provide detailed information and metrics relating to performance all the sent emails. You can set a limit to the number of reports or, for example, target a specific message or campaign.
Delivery reports provide key insights that enable you to optimize workflows, such as creating failover logic or slowing down traffic if delivery performance is not optimal.
The delivery report is returned only once. Additional delivery report requests return an empty collection.
The following are examples to get email delivery reports.
Get reports by Message ID
Use the messageId
parameter to specify a specific message. For example:
GET /email/1/reports?messageId=
Get the initial two delivery reports
Use the limit
parameter to define the maximum number of reports. For example:
GET /email/1/reports?limit=2 HTTP/1.1
Get reports by bulk ID
Use the bulkId
parameter to request the unique report.
Get reports by bulk ID
Use the bulkId
parameter to request the unique report.
GET /email/1/reports?bulkId=lrzkq6gatdkxouhrkgni HTTP/1.1
Email messages logs
The Get Email logs (opens in a new tab) method allows you to get logs for email messages. None of the query parameters is mandatory for this request. Any combination of parameters can be used to filter results. Some examples are shown below.
Email logs are available for the last 48 hours only.
Response format
If successful, the response header HTTP status code is 200 OK
and the message logs are returned.
If you try to send a message without authorization, you get a response with HTTP status code 401 Unauthorized
.
If you use this method too many times in a short period of time, you receive the 429 Too Many Requests
status code. This prevents misusing logs in cases where reports would be more appropriate.
Get logs with multiple message ID filters
The fields from
, to
, and limit
accept a single parameter, which is used to filter response message logs.
Get logs with date range and general status filters
The fields sentSince
and generalStatus
accept a single parameter, which is used to filter response message logs.
Get logs bulk ID
To use this method, use the bulkId
returned in the response for an email/emails you wish to filter message logs for.
Tracking notifications
If trackingUrl
is passed, you are notified whenever the email is opened or an URL in the email is clicked by the recipient. The structure of the data passed in the open and click notifications is shown below.
Open notifications
{
"notificationType": "OPENED",
"domain": "sendingdomain.com",
"recipient": "john.smith@somecompany.com",
"sendDateTime": 1517652288663,
"messageId": "zl3cf7frmy48ueavnnxy",
"callbackData": "Email open and click callback data",
"bulkId": "8pok2duu132mojj587zc",
"recipientInfo": {
"deviceType": "Desktop",
"os": "Windows XP",
"deviceName": "PC"
}
}
Click notifications
{
"notificationType": "CLICKED",
"domain": "sendingdomain.com",
"recipient": "jane.smith@somecompany.com",
"url": "http://www.example.com/landingpage.html",
"sendDateTime": 1517652288646,
"messageId": "zsf6q5vjgn1y6qqn65g7",
"callbackData": "Email open and click callback data",
"bulkId": "8pok2duu132mojj587zc",
"recipientInfo": {
"deviceType": "Desktop",
"os": "Windows XP",
"deviceName": "PC"
}
}