Hi,
I am trying to send an email from XSJS using HttpRequest POST method. I am trying from a month, googling, searching on sap answers portal but still could not get it working.
This is a working instance from Postman which I want to integrate with XSJS.

I tried to get this done with multiple ways, the last one is this:
var req =new $.net.http.Request($.net.http.POST,"/xxxx/xxxxx/sendmail.php");
var entity = req.entities.create();
req.contentType = "multipart/form-data";
body = body + "Content-Disposition: form-data; toEmail=\"ankurxxaa@aasc.com\"\r\n";
body = body + "Content-Disposition: form-data; subject=\"Sample Email test\"\r\n";
body = body + "Content-Disposition: form-data; rawBody=\"Raw Text body\"\r\n";
body = body + "Content-Disposition: form-data; htmlBody=\"<p>HTML Body</p>\"\r\n";
body = body + "Content-Disposition: form-data; key=\"myapikey\"";
entity.headers.set("Content-Disposition", "form-data; toEmail=\"ankurxxaa@aasc.com\"\r\n");
entity.headers.set("Content-Disposition", "form-data; subject=\"Sample Email test\"\r\n");
entity.headers.set("Content-Disposition", "form-data; rawBody=\"Raw Text body\"\r\n");
entity.headers.set("Content-Disposition", "form-data; htmlBody=\"<p>HTML Body</p>\"\r\n");
entity.headers.set("Content-Disposition", "form-data; key=\"myapikey\"\r\n");
//entity.setBody(body);
req.setBody(body);
var clientresponse = client.request(req, dest).getResponse();
$.response.status = $.net.http.OK;
$.response.setBody(clientresponse.body.asString());
And this is how it is flowing if we run from cURL:
curl -X POST \ http://aabbccddeeff/xxxx/yyyy/sendmail.php \ -H 'Cache-Control: no-cache' \ -H 'Postman-Token: ec19e174-ac78-f9a7-ade6-cef762b4e53f' \ -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \ -F toEmail=ankurasde@3vr3gf.com \ -F 'subject=Test Mail' \ -F 'rawBody=This is test mail' \ -F 'htmlBody=<p>This is <strong>test</strong> mail.<p>' \ -F 'myapikey'
It keeps on giving me error message as Payload is empty. The endpoint is based on PHP and it says
if(empty($_POST))
{
die("Payload is empty")
}
Need help from SAP experts.
Regards,
Ankur