Skip to content

class net.Mail

Ayhan Rashidov edited this page Sep 5, 2022 · 2 revisions

$.net.Mail Class

Class for constructing and sending multipart emails.

Reference

SAP Help

https://help.sap.com/doc/3de842783af24336b6305a3c0223a369/2.0.03/en-US/$.net.Mail.html

Module

https://github.com/codbex/codbex-kronos/tree/main/modules/api/api-xsjs/src/main/resources/META-INF/dirigible/kronos/net

Sample Usage

let net = $.net;

// Create email from JS Object.
let mail = new $.net.Mail({
    sender: {address: "sender@sap.com"},
    to: [{ name: "John Doe", address: "john.doe@sap.com"}, {name: "Jane Doe", address: "jane.doe@sap.com"}],
    cc: [{address: "cc1@sap.com"}, {address: "cc2@sap.com"}],
    bcc: [{ name: "Jonnie Doe", address: "jonnie.doe@sap.com"}],
    subject: "subject",
    subjectEncoding: "UTF-8",
    parts: [ new $.net.Mail.Part({
        type: $.net.Mail.Part.TYPE_TEXT,
        text: "The body of the mail.",
        contentType: "text/plain",
        encoding: "UTF-8",
    })]
});

// 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));

Coverage

  • new Mail(MailObject)
Name Type Argument Description
MailObject object optional JS object containing different part of the email in JSON format. Supported properties are {'sender', 'to', 'cc', 'bcc', 'subject', 'subjectEncoding', 'parts'}.
Classes Description Status
Part Class for constructing email parts.
Members Type Description Status
bcc array Property used for initializing "bcc" property of the mail. It is an array containing objects with three properties. The first one is the name of the person, the second one is the actual mail address, the third one is the name encoding ex. {name: "John Doe", address: "john.doe@sap.com", nameEncoding: "UTF-8"} or {name: "John Doe", address: "john.doe@sap.com"} or {address: "john.doe@sap.com"} or just "john.doe@sap.com". The name and the name encoding of the person can be skipped, but the mail address cannot. If 'address' property is not set, the mail won't be send at all.
cc array Property used for initializing "cc" property of the mail. It is an array containing objects with three properties. The first one is the name of the person, the second one is the actual mail address, the third one is the name encoding ex. {name: "John Doe", address: "john.doe@sap.com", nameEncoding: "UTF-8"} or {name: "John Doe", address: "john.doe@sap.com"} or {address: "john.doe@sap.com"} or just "john.doe@sap.com". The name and the name encoding of the person can be skipped, but the mail address cannot. If 'address' property is not set, the mail won't be send at all.
parts array Property used for initializing "parts" property of the mail. It is an array containing $.net.Mail.Part() objects.
sender object Property used for initializing "sender" property of the mail. The object contains three properties. The first one is the name of the person, the second one is the actual mail address, the third one is the name encoding ex. {name: "John Doe", address: "john.doe@sap.com", nameEncoding: "UTF-8"} or {name: "John Doe", address: "john.doe@sap.com"} or {address: "john.doe@sap.com"} or just "john.doe@sap.com". The name and the name encoding of the person can be skipped, but the mail address cannot. If 'address' property is not set, the mail won't be send at all. The "sender" property is a mandatory field, if it is not set or is not set properly the mail won't be sent.
subject string Property used for initializing "subject" property of the mail.
subjectEncoding string Property used for initializing "subjectEncoding" property of the mail. It is the encoding of the subject. If this property is not set, the default value is "UTF-8".
to array Property used for initializing "to" property of the mail. It is an array containing objects with three properties. The first one is the name of the person, the second one is the actual mail address, the third one is the name encoding ex. {name: "John Doe", address: "john.doe@sap.com", nameEncoding: "UTF-8"} or {name: "John Doe", address: "john.doe@sap.com"} or {address: "john.doe@sap.com"} or just "john.doe@sap.com". The name and the name encoding of the person can be skipped, but the mail address cannot. If 'address' property is not set, the mail won't be send at all.
Methods Return Type Description Status
send() object Returns and object that contains two properties: 'messageId' and 'finalReply'. The property 'messageId' contains the generated messageId and the property 'finalReply' contains the last reply from the mail server. It throws an error if anything is missing or there is a problem during sending/setting properties.

Unit Tests ⚠️

https://github.com/codbex/codbex-kronos/tree/main/modules/engines/engine-xsjs/src/test/resources/META-INF/dirigible/test/kronos/net

Integration Tests ❌

Wiki icons legend

✅ - Feature implemented and working as supposed.
⚠️ - Feature partially implemented and needs to be finished.
❌ - Feature not implemented yet.

Clone this wiki locally