{"_id":"59b7b572e7796d003c005626","project":"54eb50e5615ffc1900305a16","version":{"_id":"54eb63b859b1172100334fae","project":"54eb50e5615ffc1900305a16","forked_from":"54eb63a1867e1917009b711d","__v":28,"createdAt":"2015-02-23T17:30:32.501Z","releaseDate":"2015-02-23T17:30:32.501Z","categories":["54eb63b959b1172100334faf","54eb63b959b1172100334fb0","54eb63b959b1172100334fb1","54eb63b959b1172100334fb2","54ed8dd4ab373e2300f50eae","54ed99b2ab373e2300f50ede","55153a6de68daa2f00cff838","551546edbc466623002afe72","5515472ac28d6125001b8884","55154749c28d6125001b8885","555d9b4106dfec0d00d38ea7","5613e06e433e5735007c7708","5624bbb785a31117001c5403","56669e857cc81e0d00253f8e","568b8d837a42220d00498311","56a632277ef6620d00e2f18a","56d8147c3eb4dd0b00201aac","57a9ce2fac6db30e000d7efd","57a9cf4e944ea60e00dc3f74","58172386715dce0f00da4aa0","582dc59ee1b8692300c0dd03","589b19b4fec2730f0082e040","58b04a023529383900a759b5","58b92d1598157a0f004869bf","592e7685c58275000f20174f","59392839e376d4002f8a0474","59393064e376d4002f8a05a1","5947ae0d4005e2000f3a4fec","594a74df1d1de5001ab3517a","5954bc387a147f001b918915","59b8eeeb707542001076d3b6"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1"},"category":{"_id":"57a9cf4e944ea60e00dc3f74","project":"54eb50e5615ffc1900305a16","__v":0,"version":"54eb63b859b1172100334fae","sync":{"url":"","isSync":false},"reference":true,"createdAt":"2016-08-09T12:40:46.182Z","from_sync":false,"order":8,"slug":"email-messages","title":"Email messages"},"user":"58402330c0507319000634d5","__v":11,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-09-12T10:22:42.956Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[{"language":"json","status":200,"name":"","code":"{\n  \"bulkId\": \"cusotmBulkId\",\n  \"messages\": [\n    {\n      \"to\": \"jane.smith:::at:::somecompany.com\",\n      \"messageCount\": 1,\n      \"messageId\": \"c268350e-c85e-41d1-b5a0-a60771b134bd\",\n      \"status\": {\n        \"groupId\": 1,\n        \"groupName\": \"PENDING\",\n        \"id\": 7,\n        \"name\": \"PENDING_ENROUTE\",\n        \"description\": \"Message sent to next instance\"\n      }\n    }\n  ]\n}"}]},"settings":"554860d6d2c8410d006c215e","examples":{"codes":[{"code":"curl -s --user user:password \\\nhttps://api.infobip.com/email/1/send \\\n-F from='Jane Smith <jane.smith@somecompany.com>' \\\n-F to='john.smith@somedomain.com' \\\n-F replyTo='all.replies@somedomain.com' \\\n-F subject='Mail subject text' \\\n-F text='Mail body text' \\\n--form-string html='<h1>Html body</h1><p>Rich HTML message body.</p>' \\\n-F attachment=@files/image1.jpg \\\n-F bulkId='cusotmBulkId' \\\n-F intermediateReport='true' \\\n-F notifyUrl='http://www.example.com/email/advanced' \\\n-F notifyContentType = 'application/json' \\\n-F callbackData = 'DLR callback data'","language":"curl"},{"name":null,"language":"http","code":"POST /email/1/send HTTP/1.1\nHost: api.infobip.com\nAuthorization: Basic bWt1dGljMjpNdTtpMjAxMiws\nAccept: application/json\nContent-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW\n\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"from\"\n\nJane Doe <jane.doe@somecompany.com>\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"to\"\n\njohn.smith@somecompany.com\n\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"replyTo\"\n\nall.replies@somedomain.com\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"subject\"\n\nTest mail subject\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"text\"\n\nSimple text body\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"html\"\n\n<h1>Html body</h1><p>Rich HTML message body.</p>\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"attachment\"; filename=\"image1.jpg\"\nContent-Type: application/x-object\n\n... contents of file goes here ...\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"bulkId\"\n\nA_CUSTOM_BULK_ID\n------WebKitFormBoundary7MA4YWxkTrZu0gW--\nContent-Disposition: form-data; name=\"intermediateReport\" \ntrue\n\n------WebKitFormBoundary7MA4YWxkTrZu0gW--\nContent-Disposition: form-data; name=\"notifyUrl\" \nhttp://www.example.com/email/advanced\n\n------WebKitFormBoundary7MA4YWxkTrZu0gW--\nContent-Disposition: form-data; name=\"notifyContentType\" \napplication/json\n\n------WebKitFormBoundary7MA4YWxkTrZu0gW--\nContent-Disposition: form-data; name=\"callbackData\" \nDLR callback data\n\n------WebKitFormBoundary7MA4YWxkTrZu0gW--"},{"language":"php","code":"<?php\ndefine('MULTIPART_BOUNDARY', '----'.md5(time()));\ndefine('EOL',\"\\r\\n\");// PHP_EOL cannot be used for emails we need the CRFL '\\r\\n'\n\nfunction getBodyPart($FORM_FIELD, $value) {\n    if ($FORM_FIELD === 'attachment') {\n        $content = 'Content-Disposition: form-data; name=\"'.$FORM_FIELD.'\"; filename=\"'.basename($value).'\"' . EOL;\n        $content .= 'Content-Type: '.mime_content_type($value) . EOL;\n        $content .= 'Content-Transfer-Encoding: binary' . EOL;\n        $content .= EOL . file_get_contents($value) .EOL;\n    } else {\n        $content = 'Content-Disposition: form-data; name=\"' . $FORM_FIELD . '\"' . EOL;\n        $content .= EOL . $value . EOL;\n    }\n\n    return $content;\n}\n\n/*\n * Method to convert an associative array of parameters into the HTML body string\n*/\nfunction getBody($fields) {\n    $content = '';\n    foreach ($fields as $FORM_FIELD => $value) {\n        $values = is_array($value) ? $value : array($value);\n        foreach ($values as $v) {\n            $content .= '--' . MULTIPART_BOUNDARY . EOL . getBodyPart($FORM_FIELD, $v);\n        }\n    }\n    return $content . '--' . MULTIPART_BOUNDARY . '--'; // Email body should end with \"--\"\n}\n\n/*\n * Method to get the headers for a basic authentication with username and passowrd\n*/\nfunction getHeader($username, $password){\n    // basic Authentication\n    $auth = base64_encode(\"$username:$password\");\n\n    // Define the header\n    return array('Authorization:Basic '.$auth, 'Content-Type: multipart/form-data ; boundary=' . MULTIPART_BOUNDARY );\n}\n\n// URL to the API that sends the email.\n$url = 'https://api.infobip.com/email/1/send';\n\n// Associate Array of the post parameters to be sent to the API\n$postData = array(\n    'from' => 'company@somecompany.com',\n    'to' => 'john.smith@somedomain.com',\n  \t'replyTo' => 'all.replies@somedomain.com',\n    'subject' => 'Mail subject text',\n    'text' => 'Mail body text',\n    'html' => '<h1>Html body</h1><p>Rich HTML message body.</p>',\n    'attachment' => '/path/to/file/image1.jpg'\n \t\t'intermediateReport'=> 'true'\n\t\t'notifyUrl' => 'http://www.example.com/email/advanced'\n\t  'notifyContentType' => 'application/json'\n\t  'callbackData' => 'DLR callback data'\n);\n\n// Create the stream context.\n$context = stream_context_create(array(\n    'http' => array(\n          'method' => 'POST',\n          'header' => getHeader('username', 'password'),\n          'content' =>  getBody($postData),\n    )\n));\n\n// Read the response using the Stream Context.\n$response = file_get_contents($url, false, $context);\n ?>\n"},{"code":"/*----Sending fully featured email----*/\n\nfunction createFormData(data) {\n    var formData = new FormData();\n    for (var key in data) {\n        formData.append(key, data[key]);\n    }\n    return formData;\n}\n\n//Dummy File Object\nvar file = new File([\"\"], \"filename\");\n\nvar data = {\n    'from': 'Sender Name <from@example.com>',\n    'to': 'recipient1@example.com',\n    'subject': 'Test Subject',\n    'html': '<h1>Html body</h1><p>Rich HTML message body.</p>',\n    'text': 'Sample Email Body',\n    'attachment': file,\n    'intermediateReport': 'true',\n    'notifyUrl': 'http://www.example.com/email/advanced'\n};\n\n\nvar xhr = new XMLHttpRequest();\nxhr.withCredentials = false;\n\nxhr.addEventListener('readystatechange', function () {\n    if (this.readyState === this.DONE) {\n        console.log(this.responseText);\n    }\n});\n\nxhr.open('POST', 'https://api.infobip.com/email/1/send', false);\nxhr.setRequestHeader('authorization', 'Basic bWt1dGljMjpNdTtpMjAxMiws');\nxhr.setRequestHeader('accept', 'application/json');\n\nxhr.send(createFormData(data));\n","language":"javascript"},{"language":"java","code":"HttpResponse<String> response = Unirest.post(\"https://api.infobip.com/email/1/send\")\n                .header(\"Authorization\", \"Basic YXJhamhhbnNhOmF4ZGNmcnQy\")\n                .header(\"Accept\", \"application/json\")\n                .field(\"from\", \"Jane Smith <jane.smith@somecompany.com>\", \"text/plain\")\n                .field(\"to\", \"john.smith@somedomain.com\", \"text/plain\")\n                .field(\"replyTo\", \"all.replies@somedomain.com\", \"text/plain\")\n                .field(\"subject\", \"Mail subject text\", \"text/plain\")\n                .field(\"text\", \"Mail body text\", \"text/plain\")\n                .field(\"html\", \"<h1>Html body</h1><p>Rich HTML message body.</p>\", \"text/plain\")\n                .field(\"attachment\", new File(\"/tmp/image1.png\"))\n                .field(\"bulkId\", \"cusotmBulkId\",\"text/plain\")\n                .field(\"intermediateReport\", \"true\", \"text/plain\")\n                .field(\"notifyUrl\", \"http://www.example.com/email/advanced\", \"text/plain\")\n                .field(\"notifyContentType\", \"application/json\", \"text/plain\")\n                .field(\"callbackData\", \"DLR callback data\", \"text/plain\")\n                .asString();"},{"code":"HttpClient client = new HttpClient();\n            client.BaseAddress = new Uri(\"https://api.infobip.com/\");\n            client.DefaultRequestHeaders.Accept.Clear();\n            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(\"application/json\"));\n            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(\"Basic\", \"dJKDndiasdf797899ar4rkn2FtS0BiQGRkIQ\");\n            var request = new MultipartFormDataContent();            \n            request.Add(new StreamContent(File.OpenRead(filePath)), \"attachment\", new FileInfo(filePath).Name);\n            request.Add(new StringContent(\"Jane Doe <jane.doe@somecompany.com>\"), \"from\");\n            request.Add(new StringContent(\"john.smith@somedomain.com\"), \"to\");\n            request.Add(new StringContent(\"all.replies@somedomain.com\"), \"replyto\");\n            request.Add(new StringContent(\"Mail subject text\"), \"subject\");\n            request.Add(new StringContent(\"Rich HTML message body.\"), \"text\");\n            request.Add(new StringContent(\"<h1>Html body</h1><p>Rich HTML message body.</p>\"), \"html\");\n            request.Add(new StringContent(\"cusotmBulkId\"), \"bulkId\");\n            request.Add(new StringContent(\"true\"), \"intermediateReport\");\n            request.Add(new StringContent(\"http://www.example.com/email/advanced\"), \"notifyUrl\");\n            request.Add(new StringContent(\"application/json\"), \"notifyContentType\");\n            request.Add(new StringContent(\"DLR callback data\"), \"callbackData\");            \n\t    var response = client.PostAsync(\"email/1/send\", request).Result;\n            if (response.IsSuccessStatusCode) {\n                var responseContent = response.Content;\n                string responseString = responseContent.ReadAsStringAsync().Result;\n                Console.WriteLine(responseString);\n            }","language":"csharp"}]},"method":"post","auth":"required","params":[{"_id":"57a1b44e5220910e002a16c0","ref":"","in":"body","required":false,"desc":"Email address with optional sender name. Example: \"Jane Smith <<jane.smith@somecompany.com>>\"","default":"","type":"string","name":"from"},{"_id":"57a1b44e5220910e002a16bf","ref":"","in":"body","required":false,"desc":"Email address of the recipient","default":"","type":"string","name":"to"},{"_id":"5941297c8d6974000f64f9fc","ref":"","in":"body","required":false,"desc":"Email address to which recipients of the email can reply","default":"","type":"string","name":"replyTo"},{"_id":"57a1b44e5220910e002a16be","ref":"","in":"body","required":false,"desc":"Message subject","default":"","type":"string","name":"subject"},{"_id":"57a1b44e5220910e002a16bd","ref":"","in":"body","required":false,"desc":"Body of the message","default":"","type":"string","name":"text"},{"_id":"57a1c927f724ae1900df48b2","ref":"","in":"body","required":false,"desc":"HTML body of the message. If html and text fields are present, text field will be ignored and html will be delivered as message body","default":"","type":"string","name":"html"},{"_id":"57a1caa3d778850e0047e27a","ref":"","in":"body","required":false,"desc":"File attachment","default":"","type":"file","name":"attachment"},{"_id":"58bcf136b4e9640f00e4bc23","ref":"","in":"body","required":false,"desc":"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.","default":"","type":"string","name":"bulkId"},{"_id":"5926b8e76c729e0f00595ac4","ref":"","in":"body","required":false,"desc":"The real-time Intermediate delivery report that will be sent on your callback server. Can be `true` or `false`.","default":"","type":"boolean","name":"intermediateReport"},{"_id":"5926b8e76c729e0f00595ac3","ref":"","in":"body","required":false,"desc":"The URL on your callback server on which the [Delivery report](http://dev.infobip.com/v1/docs/delivery-reports) will be sent.","default":"","type":"string","name":"notifyUrl"},{"_id":"5926b8e76c729e0f00595ac2","ref":"","in":"body","required":false,"desc":"Preferred Delivery report content type. Can be `application/json` or `application/xml`.","default":"","type":"string","name":"notifyContentType"},{"_id":"5926b8e76c729e0f00595ac1","ref":"","in":"body","required":false,"desc":"Additional client's data that will be sent on the notifyUrl. The maximum value is 200 characters.","default":"","type":"string","name":"callbackData"}],"url":"/email/:version/send"},"isReference":true,"order":2,"body":"# Response format\n\nOn success, response header HTTP status code will be `200 OK` and the message will be sent.\n\nIf you try to send message without authorization, you will receive an error `401 Unauthorized`.\n\n### Response\n\n|Parameter|Type|Description|\n|-|-|-|\n|*bulkId*|String|Either a user provided custom bulk id or an auto generated one in case bulkId was absent in the request.|\n|*messages*|MessageInfo[]|Array of sent message objects, one object per every message.|\n\n### MessageInfo\n\n|Parameter|Type|Description|\n|-|-|-|\n|*to*|String|The message destination address.|\n|*status*|[Status](#section-status)|Indicates whether the message is successfully sent, not sent, delivered, not delivered, waiting for delivery or any other possible status.|\n|*messageCount*|int|The number of sent message segments.|\n|*messageId*|String|The ID that uniquely identifies the message sent.|\n\n#### Status\n\n|Parameter|Type|Description|\n|-|-|-|\n|*groupId*|int|Status [group ID](http://dev.infobip.com/v1/docs/response-codes#status-object-example).|\n|*groupName*|String|Status [group name](http://dev.infobip.com/v1/docs/response-codes#status-object-example).|\n|*id*|int|Status [ID](http://dev.infobip.com/v1/docs/response-codes#status-object-example).|\n|*name*|String|Status [name](http://dev.infobip.com/v1/docs/response-codes#section-status-object-example).|\n|*description*|String|Human readable [description](http://dev.infobip.com/v1/docs/response-codes#status-object-example) of the status.|\n|*action*|String|[Action](http://dev.infobip.com/v1/docs/response-codes#status-object-example) that should be taken to eliminate the error.|\n[block:api-header]\n{\n  \"type\": \"post\",\n  \"title\": \"Send email to multiple recipients\"\n}\n[/block]\nYou can easily send the same email to multiple recipient addresses by including more then one **to **parameters in the request\n##Example\nRequest:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl -s --user user:password \\\\\\nhttps://api.infobip.com/email/1/send \\\\\\n-F from='Jane Smith <jane.smith@somecompany.com>' \\\\\\n-F to='john.smith@somedomain.com' \\\\\\n-F to='tom.smith@somedomain.com' \\\\\\n-F subject='Mail subject text' \\\\\\n-F text='Mail body text' \\\\\\n--form-string html='<h1>Html body</h1><p>Rich HTML message body.</p>' \\\\\\n-F attachment=@files/image1.jpg\",\n      \"language\": \"curl\"\n    },\n    {\n      \"code\": \"POST /email/1/send HTTP/1.1\\nHost: api.infobip.com\\nAuthorization: Basic bWt1dGljMjpNdTtpMjAxMiws\\nAccept: application/json\\nContent-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW\\n\\n------WebKitFormBoundary7MA4YWxkTrZu0gW\\nContent-Disposition: form-data; name=\\\"from\\\"\\n\\nJane Doe <jane.doe@somecompany.com>\\n------WebKitFormBoundary7MA4YWxkTrZu0gW\\nContent-Disposition: form-data; name=\\\"to\\\"\\n\\njohn.smith@somecompany.com\\n------WebKitFormBoundary7MA4YWxkTrZu0gW\\nContent-Disposition: form-data; name=\\\"to\\\"\\n\\njane.smith@somecompany.com\\n------WebKitFormBoundary7MA4YWxkTrZu0gW\\nContent-Disposition: form-data; name=\\\"subject\\\"\\n\\nTest mail subject\\n------WebKitFormBoundary7MA4YWxkTrZu0gW\\nContent-Disposition: form-data; name=\\\"text\\\"\\n\\nSimple text body\\n------WebKitFormBoundary7MA4YWxkTrZu0gW\\nContent-Disposition: form-data; name=\\\"html\\\"\\n\\n<h1>Html body</h1><p>Rich HTML message body.</p>\\n------WebKitFormBoundary7MA4YWxkTrZu0gW\\nContent-Disposition: form-data; name=\\\"attachment\\\"; filename=\\\"image1.jpg\\\"\\nContent-Type: application/x-object\\n\\n... contents of file goes here ...\\n------WebKitFormBoundary7MA4YWxkTrZu0gW--\",\n      \"language\": \"http\"\n    },\n    {\n      \"code\": \"<?php\\ndefine('MULTIPART_BOUNDARY', '----'.md5(time()));\\ndefine('EOL',\\\"\\\\r\\\\n\\\");// PHP_EOL cannot be used for emails we need the CRFL '\\\\r\\\\n'\\n\\nfunction getBodyPart($FORM_FIELD, $value) {\\n    if ($FORM_FIELD === 'attachment') {\\n        $content = 'Content-Disposition: form-data; name=\\\"'.$FORM_FIELD.'\\\"; filename=\\\"'.basename($value).'\\\"' . EOL;\\n        $content .= 'Content-Type: '.mime_content_type($value) . EOL;\\n        $content .= 'Content-Transfer-Encoding: binary' . EOL;\\n        $content .= EOL . file_get_contents($value) .EOL;\\n    } else {\\n        $content = 'Content-Disposition: form-data; name=\\\"' . $FORM_FIELD . '\\\"' . EOL;\\n        $content .= EOL . $value . EOL;\\n    }\\n\\n    return $content;\\n}\\n\\n/*\\n * Method to convert an associative array of parameters into the HTML body string\\n*/\\nfunction getBody($fields) {\\n    $content = '';\\n    foreach ($fields as $FORM_FIELD => $value) {\\n        $values = is_array($value) ? $value : array($value);\\n        foreach ($values as $v) {\\n            $content .= '--' . MULTIPART_BOUNDARY . EOL . getBodyPart($FORM_FIELD, $v);\\n        }\\n    }\\n    return $content . '--' . MULTIPART_BOUNDARY . '--'; // Email body should end with \\\"--\\\"\\n}\\n\\n/*\\n * Method to get the headers for a basic authentication with username and passowrd\\n*/\\nfunction getHeader($username, $password){\\n    // basic Authentication\\n    $auth = base64_encode(\\\"$username:$password\\\");\\n\\n    // Define the header\\n    return array('Authorization:Basic '.$auth, 'Content-Type: multipart/form-data ; boundary=' . MULTIPART_BOUNDARY );\\n}\\n\\n// URL to the API that sends the email.\\n$url = 'https://api.infobip.com/email/1/send';\\n\\n// Associate Array of the post parameters to be sent to the API\\n$postData = array(\\n    'from' => 'company@somecompany.com',\\n    'to' => array('john.smith@somedomain.com', 'jane.smith@somedomain.com'),\\n    'subject' => 'Mail subject text',\\n    'text' => 'Mail body text',\\n    'html' => '<h1>Html body</h1><p>Rich HTML message body.</p>',\\n    'attachment' => '/path/to/file/image1.jpg'\\n);\\n\\n// Create the stream context.\\n$context = stream_context_create(array(\\n    'http' => array(\\n          'method' => 'POST',\\n          'header' => getHeader('username', 'password'),\\n          'content' =>  getBody($postData),\\n    )\\n));\\n\\n// Read the response using the Stream Context.\\n$response = file_get_contents($url, false, $context);\\n ?>\\n\",\n      \"language\": \"php\"\n    },\n    {\n      \"code\": \"/*----Sending email to multiple recipients----*/\\n\\nfunction isArray(elem) {\\n    return Object.prototype.toString.call(elem) === '[object Array]';\\n}\\n\\nfunction createFormData(data) {\\n    var formData = new FormData();\\n    for (var key in data) {\\n        if (isArray(data[key])) {\\n            for (var key2 in data[key]) {\\n                formData.append(key, data[key][key2]);\\n            }\\n        } else {\\n            formData.append(key, data[key]);\\n        }\\n    }\\n    return formData;\\n}\\n\\n//Dummy File Object\\nvar file = new File([\\\"\\\"], \\\"filename\\\");\\n\\nvar data = {\\n    'from': 'Sender Name <from@example.com>',\\n    'to': ['recipient1@example.com', 'recipient2@example.com'],\\n    'subject': 'Test Subject',\\n    'html': '<h1>Html body</h1><p>Rich HTML message body.</p>',\\n    'text': 'Sample Email Body',\\n    'attachment': file,\\n    'intermediateReport': 'true',\\n    'notifyUrl': 'http://www.example.com/email/advanced'\\n};\\n\\n\\nvar xhr = new XMLHttpRequest();\\nxhr.withCredentials = false;\\n\\nxhr.addEventListener('readystatechange', function () {\\n    if (this.readyState === this.DONE) {\\n        console.log(this.responseText);\\n    }\\n});\\n\\nxhr.open('POST', 'https://api.infobip.com/email/1/send', false);\\nxhr.setRequestHeader('authorization', 'Basic bWt1dGljMjpNdTtpMjAxMiws');\\nxhr.setRequestHeader('accept', 'application/json');\\n\\nxhr.send(createFormData(data));\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nResponse:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"bulkId\\\": \\\"lrzkq6gatdkxouhrkgni\\\",\\n  \\\"messages\\\": [\\n    {\\n      \\\"to\\\": \\\"john.smith@somecompany.com\\\",\\n      \\\"messageCount\\\": 1,\\n      \\\"messageId\\\": \\\"9129e972-be85-49ed-b0e9-f51fbd2b27c0\\\",\\n      \\\"status\\\": {\\n        \\\"groupId\\\": 1,\\n        \\\"groupName\\\": \\\"PENDING\\\",\\n        \\\"id\\\": 7,\\n        \\\"name\\\": \\\"PENDING_ENROUTE\\\",\\n        \\\"description\\\": \\\"Message sent to next instance\\\"\\n      }\\n    },\\n    {\\n      \\\"to\\\": \\\"tom.smith@somecompany.com\\\",\\n      \\\"messageCount\\\": 1,\\n      \\\"messageId\\\": \\\"cd0c5682-42e2-481a-be95-15ed72450646\\\",\\n      \\\"status\\\": {\\n        \\\"groupId\\\": 1,\\n        \\\"groupName\\\": \\\"PENDING\\\",\\n        \\\"id\\\": 7,\\n        \\\"name\\\": \\\"PENDING_ENROUTE\\\",\\n        \\\"description\\\": \\\"Message sent to next instance\\\"\\n      }\\n    }\\n  ]\\n}\",\n      \"language\": \"json\",\n      \"name\": null\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"post\",\n  \"title\": \"Send email with multiple attachments\"\n}\n[/block]\nSending email with more than one attachment is done by adding multiple attachment parameters in the request.\n##Example\nRequest:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl -s --user user:password \\\\\\nhttps://api.infobip.com/email/1/send \\\\\\n-F from='Jane Smith <jane.smith@somecompany.com>' \\\\\\n-F to='john.smith@somedomain.com' \\\\\\n-F subject='Mail subject text' \\\\\\n-F text='Mail body text' \\\\\\n--form-string html='<h1>Html body</h1><p>Rich HTML message body.</p>' \\\\\\n-F attachment=@files/image1.jpg\\n-F attachment=@files/image2.jpg\",\n      \"language\": \"curl\"\n    },\n    {\n      \"code\": \"POST /email/1/send HTTP/1.1\\nHost: api.infobip.com\\nAuthorization: Basic bWt1dGljMjpNdTtpMjAxMiws\\nAccept: application/json\\nContent-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW\\n\\n------WebKitFormBoundary7MA4YWxkTrZu0gW\\nContent-Disposition: form-data; name=\\\"from\\\"\\n\\nJane Doe <jane.doe@somecompany.com>\\n------WebKitFormBoundary7MA4YWxkTrZu0gW\\nContent-Disposition: form-data; name=\\\"to\\\"\\n\\njohn.smith@somecompany.com\\n------WebKitFormBoundary7MA4YWxkTrZu0gW\\nContent-Disposition: form-data; name=\\\"subject\\\"\\n\\nTest mail subject\\n------WebKitFormBoundary7MA4YWxkTrZu0gW\\nContent-Disposition: form-data; name=\\\"text\\\"\\n\\nSimple text body\\n------WebKitFormBoundary7MA4YWxkTrZu0gW\\nContent-Disposition: form-data; name=\\\"html\\\"\\n\\n<h1>Html body</h1><p>Rich HTML message body.</p>\\n------WebKitFormBoundary7MA4YWxkTrZu0gW\\nContent-Disposition: form-data; name=\\\"attachment\\\"; filename=\\\"image1.jpg\\\"\\nContent-Type: application/x-object\\n\\n... contents of file goes here ...\\n------WebKitFormBoundary7MA4YWxkTrZu0gW\\nContent-Disposition: form-data; name=\\\"attachment\\\"; filename=\\\"image2.jpg\\\"\\nContent-Type: application/x-object\\n\\n... contents of file goes here ...\\n------WebKitFormBoundary7MA4YWxkTrZu0gW--\",\n      \"language\": \"http\"\n    },\n    {\n      \"code\": \"<?php\\ndefine('MULTIPART_BOUNDARY', '----'.md5(time()));\\ndefine('EOL',\\\"\\\\r\\\\n\\\");// PHP_EOL cannot be used for emails we need the CRFL '\\\\r\\\\n'\\n\\nfunction getBodyPart($FORM_FIELD, $value) {\\n    if ($FORM_FIELD === 'attachment') {\\n        $content = 'Content-Disposition: form-data; name=\\\"'.$FORM_FIELD.'\\\"; filename=\\\"'.basename($value).'\\\"' . EOL;\\n        $content .= 'Content-Type: '.mime_content_type($value) . EOL;\\n        $content .= 'Content-Transfer-Encoding: binary' . EOL;\\n        $content .= EOL . file_get_contents($value) .EOL;\\n    } else {\\n        $content = 'Content-Disposition: form-data; name=\\\"' . $FORM_FIELD . '\\\"' . EOL;\\n        $content .= EOL . $value . EOL;\\n    }\\n\\n    return $content;\\n}\\n\\n/*\\n * Method to convert an associative array of parameters into the HTML body string\\n*/\\nfunction getBody($fields) {\\n    $content = '';\\n    foreach ($fields as $FORM_FIELD => $value) {\\n        $values = is_array($value) ? $value : array($value);\\n        foreach ($values as $v) {\\n            $content .= '--' . MULTIPART_BOUNDARY . EOL . getBodyPart($FORM_FIELD, $v);\\n        }\\n    }\\n    return $content . '--' . MULTIPART_BOUNDARY . '--'; // Email body should end with \\\"--\\\"\\n}\\n\\n/*\\n * Method to get the headers for a basic authentication with username and passowrd\\n*/\\nfunction getHeader($username, $password){\\n    // basic Authentication\\n    $auth = base64_encode(\\\"$username:$password\\\");\\n\\n    // Define the header\\n    return array('Authorization:Basic '.$auth, 'Content-Type: multipart/form-data ; boundary=' . MULTIPART_BOUNDARY );\\n}\\n\\n// URL to the API that sends the email.\\n$url = 'https://api.infobip.com/email/1/send';\\n\\n// Associate Array of the post parameters to be sent to the API\\n$postData = array(\\n    'from' => 'company@somecompany.com',\\n    'to' => 'john.smith@somedomain.com',\\n    'subject' => 'Mail subject text',\\n    'text' => 'Mail body text',\\n    'html' => '<h1>Html body</h1><p>Rich HTML message body.</p>',\\n    'attachment' => array('/path/to/file/image1.jpg', '/path/to/file/image2.jpg')\\n);\\n\\n// Create the stream context.\\n$context = stream_context_create(array(\\n    'http' => array(\\n          'method' => 'POST',\\n          'header' => getHeader('username', 'password'),\\n          'content' =>  getBody($postData),\\n    )\\n));\\n\\n// Read the response using the Stream Context.\\n$response = file_get_contents($url, false, $context);\\n ?>\\n\",\n      \"language\": \"php\"\n    },\n    {\n      \"code\": \"/*----Sending email with multiple attachments----*/\\n\\nfunction isArray(elem) {\\n    return Object.prototype.toString.call(elem) === '[object Array]';\\n}\\n\\nfunction createFormData(data) {\\n    var formData = new FormData();\\n    for (var key in data) {\\n        if (isArray(data[key])) {\\n            for (var key2 in data[key]) {\\n                formData.append(key, data[key][key2]);\\n            }\\n        } else {\\n            formData.append(key, data[key]);\\n        }\\n    }\\n    return formData;\\n}\\n\\n//Dummy File Objects\\nvar file1 = new File([\\\"\\\"], \\\"filename1\\\");\\nvar file2 = new File([\\\"\\\"], \\\"filename2\\\");\\n\\nvar data = {\\n    'from': 'Sender Name <from@example.com>',\\n    'to': 'recipient@example.com',\\n    'subject': 'Test Subject',\\n    'html': '<h1>Html body</h1><p>Rich HTML message body.</p>',\\n    'text': 'Sample Email Body',\\n    'attachment': [file1, file2],\\n    'intermediateReport': 'true',\\n    'notifyUrl': 'http://www.example.com/email/advanced'\\n};\\n\\n\\nvar xhr = new XMLHttpRequest();\\nxhr.withCredentials = false;\\n\\nxhr.addEventListener('readystatechange', function () {\\n    if (this.readyState === this.DONE) {\\n        console.log(this.responseText);\\n    }\\n});\\n\\nxhr.open('POST', 'https://api.infobip.com/email/1/send', false);\\nxhr.setRequestHeader('authorization', 'Basic bWt1dGljMjpNdTtpMjAxMiws');\\nxhr.setRequestHeader('accept', 'application/json');\\n\\nxhr.send(createFormData(data));\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nResponse:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"messages\\\": [\\n    {\\n      \\\"to\\\": \\\"john.smith@somecompany.com\\\",\\n      \\\"messageCount\\\": 1,\\n      \\\"messageId\\\": \\\"c268350e-c85e-41d1-b5a0-a60771b134bd\\\",\\n      \\\"status\\\": {\\n        \\\"groupId\\\": 1,\\n        \\\"groupName\\\": \\\"PENDING\\\",\\n        \\\"id\\\": 7,\\n        \\\"name\\\": \\\"PENDING_ENROUTE\\\",\\n        \\\"description\\\": \\\"Message sent to next instance\\\"\\n      }\\n    }\\n  ]\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]","excerpt":"This method allows you to send one or more email message with attachments to one or more destination addresses.","slug":"fully-featured-email","type":"endpoint","title":"Fully featured email"}

postFully featured email

This method allows you to send one or more email message with attachments to one or more destination addresses.

Definition

{{ api_url }}{{ page_api_url }}

Parameters

Body Params

from:
string
Email address with optional sender name. Example: "Jane Smith <<jane.smith@somecompany.com>>"
to:
string
Email address of the recipient
replyTo:
string
Email address to which recipients of the email can reply
subject:
string
Message subject
text:
string
Body of the message
html:
string
HTML body of the message. If html and text fields are present, text field will be ignored and html will be delivered as message body
attachment:
file
File attachment
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.
intermediateReport:
boolean
The real-time Intermediate delivery report that will be sent on your callback server. Can be `true` or `false`.
notifyUrl:
string
The URL on your callback server on which the [Delivery report](http://dev.infobip.com/v1/docs/delivery-reports) will be sent.
notifyContentType:
string
Preferred Delivery report content type. Can be `application/json` or `application/xml`.
callbackData:
string
Additional client's data that will be sent on the notifyUrl. The maximum value is 200 characters.

Examples


Result Format


Documentation

# Response format On success, response header HTTP status code will be `200 OK` and the message will be sent. If you try to send message without authorization, you will receive an error `401 Unauthorized`. ### 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](#section-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](http://dev.infobip.com/v1/docs/response-codes#status-object-example).| |*groupName*|String|Status [group name](http://dev.infobip.com/v1/docs/response-codes#status-object-example).| |*id*|int|Status [ID](http://dev.infobip.com/v1/docs/response-codes#status-object-example).| |*name*|String|Status [name](http://dev.infobip.com/v1/docs/response-codes#section-status-object-example).| |*description*|String|Human readable [description](http://dev.infobip.com/v1/docs/response-codes#status-object-example) of the status.| |*action*|String|[Action](http://dev.infobip.com/v1/docs/response-codes#status-object-example) that should be taken to eliminate the error.| [block:api-header] { "type": "post", "title": "Send email to multiple recipients" } [/block] You can easily send the same email to multiple recipient addresses by including more then one **to **parameters in the request ##Example Request: [block:code] { "codes": [ { "code": "curl -s --user user:password \\\nhttps://api.infobip.com/email/1/send \\\n-F from='Jane Smith <jane.smith@somecompany.com>' \\\n-F to='john.smith@somedomain.com' \\\n-F to='tom.smith@somedomain.com' \\\n-F subject='Mail subject text' \\\n-F text='Mail body text' \\\n--form-string html='<h1>Html body</h1><p>Rich HTML message body.</p>' \\\n-F attachment=@files/image1.jpg", "language": "curl" }, { "code": "POST /email/1/send HTTP/1.1\nHost: api.infobip.com\nAuthorization: Basic bWt1dGljMjpNdTtpMjAxMiws\nAccept: application/json\nContent-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW\n\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"from\"\n\nJane Doe <jane.doe@somecompany.com>\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"to\"\n\njohn.smith@somecompany.com\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"to\"\n\njane.smith@somecompany.com\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"subject\"\n\nTest mail subject\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"text\"\n\nSimple text body\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"html\"\n\n<h1>Html body</h1><p>Rich HTML message body.</p>\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"attachment\"; filename=\"image1.jpg\"\nContent-Type: application/x-object\n\n... contents of file goes here ...\n------WebKitFormBoundary7MA4YWxkTrZu0gW--", "language": "http" }, { "code": "<?php\ndefine('MULTIPART_BOUNDARY', '----'.md5(time()));\ndefine('EOL',\"\\r\\n\");// PHP_EOL cannot be used for emails we need the CRFL '\\r\\n'\n\nfunction getBodyPart($FORM_FIELD, $value) {\n if ($FORM_FIELD === 'attachment') {\n $content = 'Content-Disposition: form-data; name=\"'.$FORM_FIELD.'\"; filename=\"'.basename($value).'\"' . EOL;\n $content .= 'Content-Type: '.mime_content_type($value) . EOL;\n $content .= 'Content-Transfer-Encoding: binary' . EOL;\n $content .= EOL . file_get_contents($value) .EOL;\n } else {\n $content = 'Content-Disposition: form-data; name=\"' . $FORM_FIELD . '\"' . EOL;\n $content .= EOL . $value . EOL;\n }\n\n return $content;\n}\n\n/*\n * Method to convert an associative array of parameters into the HTML body string\n*/\nfunction getBody($fields) {\n $content = '';\n foreach ($fields as $FORM_FIELD => $value) {\n $values = is_array($value) ? $value : array($value);\n foreach ($values as $v) {\n $content .= '--' . MULTIPART_BOUNDARY . EOL . getBodyPart($FORM_FIELD, $v);\n }\n }\n return $content . '--' . MULTIPART_BOUNDARY . '--'; // Email body should end with \"--\"\n}\n\n/*\n * Method to get the headers for a basic authentication with username and passowrd\n*/\nfunction getHeader($username, $password){\n // basic Authentication\n $auth = base64_encode(\"$username:$password\");\n\n // Define the header\n return array('Authorization:Basic '.$auth, 'Content-Type: multipart/form-data ; boundary=' . MULTIPART_BOUNDARY );\n}\n\n// URL to the API that sends the email.\n$url = 'https://api.infobip.com/email/1/send';\n\n// Associate Array of the post parameters to be sent to the API\n$postData = array(\n 'from' => 'company@somecompany.com',\n 'to' => array('john.smith@somedomain.com', 'jane.smith@somedomain.com'),\n 'subject' => 'Mail subject text',\n 'text' => 'Mail body text',\n 'html' => '<h1>Html body</h1><p>Rich HTML message body.</p>',\n 'attachment' => '/path/to/file/image1.jpg'\n);\n\n// Create the stream context.\n$context = stream_context_create(array(\n 'http' => array(\n 'method' => 'POST',\n 'header' => getHeader('username', 'password'),\n 'content' => getBody($postData),\n )\n));\n\n// Read the response using the Stream Context.\n$response = file_get_contents($url, false, $context);\n ?>\n", "language": "php" }, { "code": "/*----Sending email to multiple recipients----*/\n\nfunction isArray(elem) {\n return Object.prototype.toString.call(elem) === '[object Array]';\n}\n\nfunction createFormData(data) {\n var formData = new FormData();\n for (var key in data) {\n if (isArray(data[key])) {\n for (var key2 in data[key]) {\n formData.append(key, data[key][key2]);\n }\n } else {\n formData.append(key, data[key]);\n }\n }\n return formData;\n}\n\n//Dummy File Object\nvar file = new File([\"\"], \"filename\");\n\nvar data = {\n 'from': 'Sender Name <from@example.com>',\n 'to': ['recipient1@example.com', 'recipient2@example.com'],\n 'subject': 'Test Subject',\n 'html': '<h1>Html body</h1><p>Rich HTML message body.</p>',\n 'text': 'Sample Email Body',\n 'attachment': file,\n 'intermediateReport': 'true',\n 'notifyUrl': 'http://www.example.com/email/advanced'\n};\n\n\nvar xhr = new XMLHttpRequest();\nxhr.withCredentials = false;\n\nxhr.addEventListener('readystatechange', function () {\n if (this.readyState === this.DONE) {\n console.log(this.responseText);\n }\n});\n\nxhr.open('POST', 'https://api.infobip.com/email/1/send', false);\nxhr.setRequestHeader('authorization', 'Basic bWt1dGljMjpNdTtpMjAxMiws');\nxhr.setRequestHeader('accept', 'application/json');\n\nxhr.send(createFormData(data));", "language": "javascript" } ] } [/block] Response: [block:code] { "codes": [ { "code": "{\n \"bulkId\": \"lrzkq6gatdkxouhrkgni\",\n \"messages\": [\n {\n \"to\": \"john.smith@somecompany.com\",\n \"messageCount\": 1,\n \"messageId\": \"9129e972-be85-49ed-b0e9-f51fbd2b27c0\",\n \"status\": {\n \"groupId\": 1,\n \"groupName\": \"PENDING\",\n \"id\": 7,\n \"name\": \"PENDING_ENROUTE\",\n \"description\": \"Message sent to next instance\"\n }\n },\n {\n \"to\": \"tom.smith@somecompany.com\",\n \"messageCount\": 1,\n \"messageId\": \"cd0c5682-42e2-481a-be95-15ed72450646\",\n \"status\": {\n \"groupId\": 1,\n \"groupName\": \"PENDING\",\n \"id\": 7,\n \"name\": \"PENDING_ENROUTE\",\n \"description\": \"Message sent to next instance\"\n }\n }\n ]\n}", "language": "json", "name": null } ] } [/block] [block:api-header] { "type": "post", "title": "Send email with multiple attachments" } [/block] Sending email with more than one attachment is done by adding multiple attachment parameters in the request. ##Example Request: [block:code] { "codes": [ { "code": "curl -s --user user:password \\\nhttps://api.infobip.com/email/1/send \\\n-F from='Jane Smith <jane.smith@somecompany.com>' \\\n-F to='john.smith@somedomain.com' \\\n-F subject='Mail subject text' \\\n-F text='Mail body text' \\\n--form-string html='<h1>Html body</h1><p>Rich HTML message body.</p>' \\\n-F attachment=@files/image1.jpg\n-F attachment=@files/image2.jpg", "language": "curl" }, { "code": "POST /email/1/send HTTP/1.1\nHost: api.infobip.com\nAuthorization: Basic bWt1dGljMjpNdTtpMjAxMiws\nAccept: application/json\nContent-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW\n\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"from\"\n\nJane Doe <jane.doe@somecompany.com>\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"to\"\n\njohn.smith@somecompany.com\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"subject\"\n\nTest mail subject\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"text\"\n\nSimple text body\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"html\"\n\n<h1>Html body</h1><p>Rich HTML message body.</p>\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"attachment\"; filename=\"image1.jpg\"\nContent-Type: application/x-object\n\n... contents of file goes here ...\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"attachment\"; filename=\"image2.jpg\"\nContent-Type: application/x-object\n\n... contents of file goes here ...\n------WebKitFormBoundary7MA4YWxkTrZu0gW--", "language": "http" }, { "code": "<?php\ndefine('MULTIPART_BOUNDARY', '----'.md5(time()));\ndefine('EOL',\"\\r\\n\");// PHP_EOL cannot be used for emails we need the CRFL '\\r\\n'\n\nfunction getBodyPart($FORM_FIELD, $value) {\n if ($FORM_FIELD === 'attachment') {\n $content = 'Content-Disposition: form-data; name=\"'.$FORM_FIELD.'\"; filename=\"'.basename($value).'\"' . EOL;\n $content .= 'Content-Type: '.mime_content_type($value) . EOL;\n $content .= 'Content-Transfer-Encoding: binary' . EOL;\n $content .= EOL . file_get_contents($value) .EOL;\n } else {\n $content = 'Content-Disposition: form-data; name=\"' . $FORM_FIELD . '\"' . EOL;\n $content .= EOL . $value . EOL;\n }\n\n return $content;\n}\n\n/*\n * Method to convert an associative array of parameters into the HTML body string\n*/\nfunction getBody($fields) {\n $content = '';\n foreach ($fields as $FORM_FIELD => $value) {\n $values = is_array($value) ? $value : array($value);\n foreach ($values as $v) {\n $content .= '--' . MULTIPART_BOUNDARY . EOL . getBodyPart($FORM_FIELD, $v);\n }\n }\n return $content . '--' . MULTIPART_BOUNDARY . '--'; // Email body should end with \"--\"\n}\n\n/*\n * Method to get the headers for a basic authentication with username and passowrd\n*/\nfunction getHeader($username, $password){\n // basic Authentication\n $auth = base64_encode(\"$username:$password\");\n\n // Define the header\n return array('Authorization:Basic '.$auth, 'Content-Type: multipart/form-data ; boundary=' . MULTIPART_BOUNDARY );\n}\n\n// URL to the API that sends the email.\n$url = 'https://api.infobip.com/email/1/send';\n\n// Associate Array of the post parameters to be sent to the API\n$postData = array(\n 'from' => 'company@somecompany.com',\n 'to' => 'john.smith@somedomain.com',\n 'subject' => 'Mail subject text',\n 'text' => 'Mail body text',\n 'html' => '<h1>Html body</h1><p>Rich HTML message body.</p>',\n 'attachment' => array('/path/to/file/image1.jpg', '/path/to/file/image2.jpg')\n);\n\n// Create the stream context.\n$context = stream_context_create(array(\n 'http' => array(\n 'method' => 'POST',\n 'header' => getHeader('username', 'password'),\n 'content' => getBody($postData),\n )\n));\n\n// Read the response using the Stream Context.\n$response = file_get_contents($url, false, $context);\n ?>\n", "language": "php" }, { "code": "/*----Sending email with multiple attachments----*/\n\nfunction isArray(elem) {\n return Object.prototype.toString.call(elem) === '[object Array]';\n}\n\nfunction createFormData(data) {\n var formData = new FormData();\n for (var key in data) {\n if (isArray(data[key])) {\n for (var key2 in data[key]) {\n formData.append(key, data[key][key2]);\n }\n } else {\n formData.append(key, data[key]);\n }\n }\n return formData;\n}\n\n//Dummy File Objects\nvar file1 = new File([\"\"], \"filename1\");\nvar file2 = new File([\"\"], \"filename2\");\n\nvar data = {\n 'from': 'Sender Name <from@example.com>',\n 'to': 'recipient@example.com',\n 'subject': 'Test Subject',\n 'html': '<h1>Html body</h1><p>Rich HTML message body.</p>',\n 'text': 'Sample Email Body',\n 'attachment': [file1, file2],\n 'intermediateReport': 'true',\n 'notifyUrl': 'http://www.example.com/email/advanced'\n};\n\n\nvar xhr = new XMLHttpRequest();\nxhr.withCredentials = false;\n\nxhr.addEventListener('readystatechange', function () {\n if (this.readyState === this.DONE) {\n console.log(this.responseText);\n }\n});\n\nxhr.open('POST', 'https://api.infobip.com/email/1/send', false);\nxhr.setRequestHeader('authorization', 'Basic bWt1dGljMjpNdTtpMjAxMiws');\nxhr.setRequestHeader('accept', 'application/json');\n\nxhr.send(createFormData(data));", "language": "javascript" } ] } [/block] Response: [block:code] { "codes": [ { "code": "{\n \"messages\": [\n {\n \"to\": \"john.smith@somecompany.com\",\n \"messageCount\": 1,\n \"messageId\": \"c268350e-c85e-41d1-b5a0-a60771b134bd\",\n \"status\": {\n \"groupId\": 1,\n \"groupName\": \"PENDING\",\n \"id\": 7,\n \"name\": \"PENDING_ENROUTE\",\n \"description\": \"Message sent to next instance\"\n }\n }\n ]\n}", "language": "json" } ] } [/block]