Skip to Content
0

How to attach files to an email in XS?

Apr 12, 2017 at 08:56 AM

151

avatar image

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;
firstPart.data = 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: "demo@sap.com"},
    to: [{name: "Mat", address: "youremail@domain.com"}],
    subject: "subject",
    subjectEncoding: "UTF-8"
});


mail.parts.push(firstPart, thirdPart);
mail.send();
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Mat Beerkens
Apr 12, 2017 at 10:56 AM
0

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

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