This repository has been archived by the owner on Aug 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
class net.Mail.Part
Ayhan Rashidov edited this page Oct 8, 2021
·
3 revisions
Class for constructing email parts.
- SAP Help
https://help.sap.com/doc/3de842783af24336b6305a3c0223a369/2.0.03/en-US/$.net.Mail.Part.html
- Module
https://github.com/SAP/xsk/tree/main/modules/api/api-xsjs/src/main/resources/xsk/net
- Sample usage:
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: "[email protected]"},
to: [{name: "to1", address: "[email protected]"}, {name: "to2", address: "[email protected]"}],
cc: [{ name: "cc1", address: "[email protected]"}, { name: "cc2", address: "[email protected]"}],
bcc: [{ name: "bcc1", address: "[email protected]"}],
subject: "subject",
subjectEncoding: "UTF-8"
});
mail.parts.push(attachmentPart, inlinePart, textPart);
// Set mail server configurations.
let mailConfig = {
"mail.user": "<your-user>",
"mail.password": "<your-password>",
"mail.transport.protocol": "smtps",
"mail.smtps.host": "<your-mail-provider-host>",
"mail.smtps.port": "465",
"mail.smtps.auth": "true"
};
let returnValue = mail.send(mailConfig);
$.response.setBody(JSON.stringify(returnValue));
- new Part(PartObject)
Name | Type | Argument | Description |
---|---|---|---|
PartObject | object | optional | JS object containing elements of a Part in JSON format. |
- Coverage
Members | Type | Description | Status |
---|---|---|---|
alternative | string | Property used for initializing "alternative" property of the text $.net.Mail.Part object. | ✅ |
alternativeContentType | string | 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". | ✅ |
contentId | string | Property used for initializing "contentId" property of the inline $.net.Mail.Part object. | ✅ |
contentType | string | Property used for initializing "contentType" property of the $.net.Mail.Part object. | ✅ |
data | string / ArrayBuffer | Property used for initializing "data" property of the attachment and inline $.net.Mail.Part object. | ✅ |
encoding | string | 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". | ✅ |
fileName | string | 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". | ✅ |
fileNameEncoding | string | 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". | ✅ |
text | string | Property used for initializing "text" property of the text $.net.Mail.Part object. | ✅ |
type | string | Property used for initializing "type" property of the |
✅ |
- Issues
- Unit Tests
- Integration Tests ❌
✅ - Feature implemented and working as supposed.
❌ - Feature not implemented yet.