Class: Mail

$.net. Mail

Class for constructing and sending multipart emails

new Mail(MailObject)

Parameters:
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'}.
Examples
//create empty $.net.Mail
var mail = new $.net.Mail();
//create email from JS Object and send
var mail = new $.net.Mail({
   sender: {address: "sender@sap.com"},
   to: [{ name: "John Doe", address: "john.doe@sap.com", nameEncoding: "US-ASCII"}, {name: "Jane Doe", address: "jane.doe@sap.com"}],
   cc: ["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",
   })]
});
var returnValue = mail.send();
var response = "MessageId = " + returnValue.messageId + ", final reply = " + returnValue.finalReply;

$.response.status = $.net.http.OK;
$.response.contentType = "text/html";
$.response.setBody(response);

Classes

Part

Members

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.
Type:
  • array

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.
Type:
  • array

parts :array

Property used for initializing "parts" property of the mail. It is an array containing $.net.Mail.Part() objects.
Type:
  • array

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.
Type:
  • object

subject :string

Property used for initializing "subject" property of the mail
Type:
  • string

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".
Type:
  • string

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.
Type:
  • array

Methods

send() → {object}

Throws:
Will throw an error if information is missing or there is an error during sending or setting the properties.
Returns:
The object 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.
Type
object
Example
var mail = new $.net.Mail();
mail.subject = "About what the email is."
mail.subjectEncoding = "UTF-8";
mail.sender = {address: "from@sap.com"};
mail.to.push({name: "John Doe", address: "john.doe@sap.com", nameEncoding: "US-ASCII"});
mail.cc = [{name: "Cc1", address: "cc1@recepient.com"}, {address: "cc2@recepient.com"}];
mail.parts.push(new $.net.Mail.Part({type: $.net.Mail.Part.TYPE_TEXT, text: 'Text'}));

var returnValue;
var response = "";

try {
    returnValue = mail.send();
} catch(error) {
    response = "Error occurred:" + error.message;
}
response = "MessageId = " + returnValue.messageId + ", final reply = " + returnValue.finalReply;

$.response.status = $.net.http.OK;
$.response.contentType = "text/html";
$.response.setBody(response);