$.net.Mail.Part
$.net.Mail.Part
class for constructing email parts.
Overview
- Definition: https://github.com/SAP/xsk/issues/19
- Module: net/net.js
- Status:
alpha
Sample Usage
Note
Requires a running mail server. If mailConfig
is not set the api defaults to a local mail server.
For more information please take a look here.
var files = require("io/v4/files");
// Getting the byte array of the attachment.
var xskLogo = files.readBytes('path-to-file/xsk-logo.png');
// Create an attachment $.net.Mail.Part from JSObject.
var attachmentPart = new $.net.Mail.Part({
type: $.net.Mail.Part.TYPE_ATTACHMENT,
data: xskLogo,
contentType: "image/png",
fileName: "xsk-logo.png",
fileNameEncoding: "UTF-8"
});
// Getting the byte array of the inline image.
var sapLogo = files.readBytes('path-to-file/sap-logo.png');
// Create an inline $.net.Mail.Part from JSObject.
var inlinePart = new $.net.Mail.Part({
type: $.net.Mail.Part.TYPE_INLINE,
data: sapLogo,
contentType: "image/png",
contentId: "IMAGE1_ID", // The content id is used in the text part to display the image in the mail body.
fileName: "sap-logo.png",
fileNameEncoding: "UTF-8"
});
// Create a text $.net.Mail.Part object.
var textPart = new $.net.Mail.Part({
type: $.net.Mail.Part.TYPE_TEXT,
text: "<html><head></head><body><h1>This is XSK</h1><br><img src=\"cid:IMAGE1_ID\"><br></body></html>",
contentType: "text/html",
encoding: "UTF-8"
});
// Create an $.net.Mail object.
var mail = new $.net.Mail({
sender: {address: "sender@sap.com"},
to: [{name: "to1", address: "to1@sap.com"}, {name: "to2", address: "to2@sap.com"}],
cc: [{ name: "cc1", address: "cc1@sap.com"}, { name: "cc2", address: "cc2@sap.com"}],
bcc: [{ name: "bcc1", address: "bcc1@sap.com"}],
subject: "subject",
subjectEncoding: "UTF-8"
});
mail.parts.push(attachmentPart, inlinePart, textPart);
let returnValue = mail.send();
$.response.setBody(JSON.stringify(returnValue));
Constructors
new $.net.Mail.Part(PartObject)
Parameters
Parameter Name | Description | Required | Type |
---|---|---|---|
PartObject | JS object containing elements of a Part in JSON format. | optional |
object |
Properties
Name | Description | Type |
---|---|---|
alternative | Property used for initializing "alternative" property of the text $.net.Mail.Part object. | string |
alternativeContentType | Property used for initializing "alternativeContentType" property of the text $.net.Mail.Part object. If this property is not set, the default value is "text/plain". | string |
contentId | Property used for initializing "contentId" property of the inline $.net.Mail.Part object. | string |
contentType | Property used for initializing "contentType" property of the $.net.Mail.Part object. | string |
data | Property used for initializing "data" property of the attachment and inline $.net.Mail.Part object. | string/ArrayBuffer |
encoding | Property used for initializing "encoding" property of the text $.net.Mail.Part object. It also applies to alternative text. If this property is not set, the default value is "UTF-8". | string |
fileName | Property used for initializing "fileName" property of the attachment and inline $.net.Mail.Part object. It contains the full name of the file with the extension, example "file.txt". | string |
fileNameEncoding | Property used for initializing "fileNameEncoding" property of the attachment and inline $.net.Mail.Part object. It is the encoding of the filename. If this property is not set, the default value is "UTF-8". | string |
text | Property used for initializing "text" property of the text $.net.Mail.Part object. | string |
type | Property used for initializing "type" property of the $.net.Mail.Part object. If this property is not set, the part will not be set. It should be one of the following: $.net.Mail.Part.TYPE_TEXT $.net.Mail.Part.TYPE_ATTACHMENT $.net.Mail.Part.TYPE_INLINE | string |
See common content types here.