Skip to Content

How to attach files to an email in XS?

I've setup emailing via the SAP HANA XS stack. This works like a charm.

Now i am trying

  1. To get an attachment to be sent with the email
  2. Get the image to show in the email html markup

I've looked at the XS API which has a pretty good description of how to do this.

The thing is that I cannot get this working. What i've tried so far:

  • put in a base64 string of an image
  • $.util.stringify($.util.codec.decodeBase64(_base64))

None are working.

function getImage() {
	var b64 = "iVBORw0KGgoAAA.........PwAhvzX8p9cHNAAAAABJRU5ErkJggg==";
	return b64;
}// Create an inline $.net.Mail.Part from JSObject.
var firstPart = new $.net.Mail.Part();
firstPart.type = $.net.Mail.Part.TYPE_INLINE; = getImage(); // data1 contains the binary data of the image
firstPart.contentType = "image/png";
firstPart.contentId = "IMAGE1_ID";
firstPart.fileName = "fileName1.png";
firstPart.fileNameEncoding = "UTF-8";

// Create a text $.net.Mail.Part object.
var thirdPart = new $.net.Mail.Part();
thirdPart.type = $.net.Mail.Part.TYPE_TEXT;
thirdPart.text = "<html><head></head><body><p>image:</p><img src=\"cid:IMAGE1_ID\"><p>end</p></body></html>";
thirdPart.contentType = "text/html";
thirdPart.alternative = "The alternative of the text";
thirdPart.alternativeContentType = "text/plain";
thirdPart.encoding = "UTF-8";

// Create an $.net.Mail object.
var mail = new $.net.Mail({
    sender: {address: ""},
    to: [{name: "Mat", address: ""}],
    subject: "subject",
    subjectEncoding: "UTF-8"
});, thirdPart);
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Apr 12, 2017 at 10:56 AM

    Allright, i got it solved. In function getImage, do the following:

    function getImage() {
    	var b64 = "iVBORw0KGgoAAA.........PwAhvzX8p9cHNAAAAABJRU5ErkJggg==";
    	return $.util.codec.decodeBase64(b64);
    Add comment
    10|10000 characters needed characters exceeded