Skip to content

$.net.Mail

$.net.Mail class for constructing and sending multi-part emails.

Overview

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.

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

Constructors

new $.net.Mail(MailObject)

Parameters

Parameter Name Description Required Type
MailObject JS object containing different part of the email in JSON format. Supported properties are {'sender', 'to', 'cc', 'bcc', 'subject', 'subjectEncoding', 'parts'}. optional object

Classes

Classes Description
Part Class for constructing email parts.

Properties

Name Description Type
bcc Property used for initializing "bcc" property of the mail. It is an array containing objects with three properties - name, encoding and address with address being required. array
cc Property used for initializing "cc" property of the mail. It is an array containing objects with three properties - name, encoding and address with address being required. array
parts Property used for initializing "parts" property of the mail. It is an array containing $.net.Mail.Part() objects. array
sender Property used for initializing "sender" property of the mail. It is an array containing objects with three properties - name, encoding and address with address being required. This property is required or the mail won't be sent. object
subject Property used for initializing "subject" property of the mail. string
subjectEncoding 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". string
to Property used for initializing "to" property of the mail. It is an array containing objects with three properties - name, encoding and address with address being required. array

Functions

Function Description Returns
send(mailConfig) method that returns an object containing two properties: 'messageId' and 'finalReply'. object

mailConfig Properties

Property Description Type
mail.user The mailbox user string
mail.password The mailbox password string
mail.transport.protocol (optional) The mail transport protocol, default is smtps string
mail.smtps.host The mail SMPTPS host string
mail.smtps.port The mail SMPTPS port number as string
mail.smtps.auth Enable/Disable mail SMPTPS authentication boolean as string
mail.smtp.host The mail SMPTP host string
mail.smtp.port The mail SMPTP port number as string
mail.smtp.auth Enable/Disable mail SMPTP authentication boolean as string

Addition mail client options can be found here: - SMTP/SMTPS - IMAP - POP3