on 2018 Feb 11 7:46 AM
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
Request clarification before answering.
Also - I am not sure if you are only using PHP to send emails, but you can configure your HANA/XS instance to do the same. If you are interesting, check out this GIST: https://gist.github.com/paschmann/144fea92015428bd773adfee290ca637
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
10 | |
9 | |
8 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.