Simple email

This method allows you to send a single email message to one destination address.

Resource

https://api.infobip.com/email/1/send

Parameters

Property name Type Description
from string Email address with optional sender name. Example: "Jane Doe <jane.doe@somecompany.com>"
to string Email address of the recipient
subject string Message subject
text string Body of message
bulkId string The ID uniquely identifies the sent Email request. This filter will enable you to query delivery reports for all the messages using just one request. You will receive a bulkId in the response after sending an Email request. If you don't set your own bulkId, unique ID will be generated by our system and returned in the API response.

Request Example

					curl -s --user user:password \
https://api.infobip.com/email/1/send \
-F from='Jane Doe <jane.doe@somecompany.com>' \
-F to='john.smith@somedomain.com' \
-F subject='Mail subject text' \
-F text='Mail body text' \
-F bulkId='cusotmBulkId'
					
				
					POST /email/1/send HTTP/1.1
Host: api.infobip.com
Authorization: Basic bWt1dGljMjpNdTtpMjAxMiws
Accept: application/json
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="from"

Jane Doe <jane.doe@somecompany.com>
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="to"

john.smith@somedomain.com
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="subject"

Mail subject text
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="text"

Mail body text
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="bulkId"

A_CUSTOM_BULK_ID
------WebKitFormBoundary7MA4YWxkTrZu0gW--
					
				
					<?php
define('MULTIPART_BOUNDARY','-----------------------'.md5(time()));
define('EOL',"\r\n");// PHP_EOL cannot be used for emails we need the CRFL '\r\n'

/*
 * Method to convert an associative array of parameters into the HTML body string
*/
function getBody($fields) {
    $content = '';
    foreach ($fields as $FORM_FIELD => $value) {
        $content .= '--' . MULTIPART_BOUNDARY . EOL;
        $content .= 'Content-Disposition: form-data; name="' . $FORM_FIELD . '"' . EOL;
        $content .= EOL . $value . EOL;
    }
    return $content . '--' . MULTIPART_BOUNDARY . '--'; // Email body should end with "--"
}

/*
 * Method to get the headers for a basic authentication with username and passowrd
*/
function getHeader($username, $password){
    // basic Authentication
    $auth = base64_encode("$username:$password");

    // Define the header
    return array("Authorization:Basic $auth", 'Content-Type: multipart/form-data ; boundary=' . MULTIPART_BOUNDARY );
}

// URL to the API that sends the email.
$url = 'https://api.infobip.com/email/1/send';

// Associate Array of the post parameters to be sent to the API
$postData = array(
    'from' => 'company@somecompany.com',
    'to' => 'john.smith@somedomain.com',
    'subject' => 'Mail subject text',
    'text' => 'Mail body text',
);

// Create the stream context.
$context = stream_context_create(array(
    'http' => array(
          'method' => 'POST',
          'header' => getHeader('username', 'password'),
          'content' =>  getBody($postData),
    )
));

// Read the response using the Stream Context.
$response = file_get_contents($url, false, $context);
var
 ?>

					
				
					/*----Sending single email----*/

var formData = new FormData();
formData.append('from', 'Example <from@example.com>');
formData.append('to', 'recipient@example.com');
formData.append('subject', 'Test subject');
formData.append('text', 'Sample Email Body');

var xhr = new XMLHttpRequest();
xhr.withCredentials = false;

xhr.addEventListener('readystatechange', function () {
    if (this.readyState === this.DONE) {
        console.log(this.responseText);
    }
});

xhr.open('POST', 'https://api.infobip.com/email/1/send', false);
xhr.setRequestHeader('authorization', 'Basic bWt1dGljMjpNdTtpMjAxMiws');
xhr.setRequestHeader('accept', 'application/json');

xhr.send(formData);
					
				
					ContentType PLAIN_UTF8 = ContentType.create("text/plain", StandardCharsets.UTF_8);

        HttpClient httpClient =  HttpClients.custom()
                .setConnectionManager(new PoolingHttpClientConnectionManager())
                .build();

        HttpPost httpPost = new HttpPost("https://api.infobip.com/email/1/send");
        httpPost.setHeader("authorization", "Basic YXJhamhhbnNhOmF4ZGNmcnQyMz");

        MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
        entityBuilder.addPart("from", new StringBody("Jane Doe <jane.doe@somecompany.com>", PLAIN_UTF8));
        entityBuilder.addPart("to", new StringBody("john.smith@somedomain.com", PLAIN_UTF8));
        entityBuilder.addPart("subject", new StringBody("Mail subject text", PLAIN_UTF8));
        entityBuilder.addPart("text", new StringBody("Mail body text", PLAIN_UTF8));

        httpPost.setEntity(entityBuilder.build());
        HttpResponse httpResponse = httpClient.execute(httpPost);
					
				
					HttpClient client = new HttpClient();
            client.BaseAddress = new Uri("https://api.infobip.com/");
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", "dJKDndiasdf797899ar4rkn2FtS0BiQGRkIQ");
            var request = new MultipartFormDataContent();            
            request.Add(new StringContent("Jane Doe <jane.doe@somecompany.com>"), "from");
            request.Add(new StringContent("john.smith@somedomain.com"), "to");
            request.Add(new StringContent("Mail subject text"), "subject");
            request.Add(new StringContent("Rich HTML message body."), "text");
	    var response = client.PostAsync("email/1/send", request).Result;
            if (response.IsSuccessStatusCode) {
                var responseContent = response.Content;
                string responseString = responseContent.ReadAsStringAsync().Result;
                Console.WriteLine(responseString);
            }
					
				

Response

					{
  "bulkId":"cusotmBulkId",
  "messages": [
    {
      "to": "john.smith@somedomain.com",
      "messageCount": 1,
      "messageId": "c268350e-c85e-41d1-b5a0-a60771b134bd",
      "status": {
        "groupId": 1,
        "groupName": "PENDING",
        "id": 7,
        "name": "PENDING_ENROUTE",
        "description": "Message sent to next instance"
      }
    }
  ]
}
					
				

Response format

If successful, the response header HTTP status code will be 200 OK and the message will be sent.

If you try to send a message without authorization, you will receive a 401 Unauthorized error .

Response

Parameter Type Description
bulkId String Either a user provided custom bulk id or an auto generated one in case bulkId was absent in the request.
messages MessageInfo Array of sent message objects, one object per every message.

MessageInfo

Parameter Type Description
to String The message destination address.
status Status Indicates whether the message is successfully sent, not sent, delivered, not delivered, waiting for delivery or any other possible status.
messageCount int The number of sent message segments.
messageId String The ID that uniquely identifies the message sent.

Status

Parameter Type Description
groupId int Status group ID.
groupName String Status group name.
id int Status ID.
name String Status name.
description String Human-readable description of the status.
action String Action that should be taken to eliminate the error.