Email Host Object
1.0 Introduction
The Email host object allows users to send out email from their mashups. It helps notify users of certain events and acts as a bridge between mashups and users.
1.1 Example
var email = new Email("host", "port", "username", "password");
var file = new File("temp.txt");
email.from = "keith@wso2.com";
email.to = "keith@wso2.com"; // alternatively message.to can be a array of strings. Same goes for cc and bcc
email.cc = "keith@wso2.com";
email.bcc = "keith@wso2.com";
email.subject = "WSO2 Mashup server 1.0 Released";
email.addAttachement(file, "temp.txt"); // Optionally can add attachements, it has a variable number of arguments. each argument can be a File hostObject or a string representing a file.
// In this case we are sending two attachments (This demontrates sending attachments using either a File Host Object or a path to the file).
email.text = "WSO2 Mashup server 1.0 was Released on 28th January 2008";
email.send();
2.0 Email Object
2.1 Email Object Constructors
The Email Object has three different constructors. Choose one depending on your configuration and your needs.
-
The constructor needs to be given configuration details as follows:
var email = new Email("smtp.gmail.com", "25", "username@gmail.com", "password"); // host, port, username, password -
The second is a slight variant of the first constructor. It does not
require a port to be specified:
var email = new Email("smtp.gmail.com", "username@gmail.com", "password"); // host, username, password
2.2 API Documentation
| Member | Description |
| void from(string from)* | An optional property to set the "from" address of the
email to
be sent. If not set the user account used to authenticate against the
email gateway will be sent as the "from" address.
email.from = "keith@wso2.com"; |
| void to(String to) | This is a required property that denotes the "to"
address of the
email to be sent. (Optionally an array of strings denoting the "to"
addresses can be passed as below.)
email.to = "keith@wso2.com"; |
| void to(Array to) | This is a required property that denotes the "to"
addresses of the email to
be sent. (Optionally a string denoting a single "to" address can
be passed as above.)
var to = new Array(); to[0] = "jonathan@wso2.com"; to[1] = "keith@wso2.com"; email.to = to; |
| void cc(String cc)* | This is an optional property that denotes the "cc"
address of the email to
be sent. (Optionally an array of strings denoting the "cc" addresses
can
be passed as below.)
email.cc = "keith@wso2.com"; |
| void cc(Array cc)* | This is an optional property that denotes the "cc"
addresses of the email to
be sent. (Optionally a string denoting a single "cc" address can
be passed as above.)
var cc = new Array(); cc[0] = "jonathan@wso2.com"; cc[1] = "keith@wso2.com"; email.cc= cc; |
| void bcc(String bcc)* | This is an optional property that denotes the "bcc"
address of the email to
be sent. (Optionally an array of strings denoting the "bcc" addresses
can
be passed as below.)
email.bcc = "keith@wso2.com"; |
| void bcc(Array bcc)* | This is an optional property that denotes the "bcc"
addresses of the email to
be sent. (Optionally a string denoting a single "bcc" address can
be passed as above.)
var bcc = new Array(); bcc[0] = "jonathan@wso2.com"; bcc[1] = "keith@wso2.com"; email.bcc = bcc; |
| void subject(String subject ) | An optional property to set the subject of the email to
be sent.
email.subject = "WSO2 Mashup server 1.0 Released"; |
| void text(String text) | An optional property to set the body text of the email
to be sent.
email.text = "WSO2 Mashup server 1.0 was Released on 28th January 2008"; |
| void html(String html | XML html) | An optional property to set the body of the email
to be sent. This function can be used to send HTML mail.
email.html = "<h1>WSO2 Mashup server 1.0 was Released on 28th January 2008</h1>"; // Setthing the HTML content as a String OR email.html = <h1>WSO2 Mashup server 1.0 was Released on 28th January 2008</h1>; // Setting the HTML content as an XML object |
| void addAttachment([String filePath]* [FileHostObject file]*) | An optional property to add attchments to the email
been sent. This function has a variable number of arguments,
each argument can
be a File hostObject or a string representing a file.
var file = new File("temp.txt"); // A file exists at temp.txt email.addAttachement(file, "temp.txt"); |
| void send() | Used to send the email. |