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 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.
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 first constructor takes no parameters and uses configuration information specified in the server.xml. Using a configuration such as this is useful if you want to use a default email account to send out mail from your mashups. It also reduces the hassle of having to key in the configuration details each time you need a new email object.
var email = new Email();
The configuration in the server.xml should be in the following form: (The default server.xml has some prepopulated dummy values. Please update them as required.)
<!--Used to configure your default email account that will be used to send emails from mashups
using the Email host Object-->
<EmailConfig>
<host>smtp.gmail.com</host>
<port>25</port>
<username>username@gmail.com</username>
<password>password</password>
</EmailConfig>Note: Changes to the server.xml require a server restart.
-
The second constructor, unlike the first, requires the user to provide the configuration details each time he creates a new email object. The benefit is that no server configuration is needed and you can use diffent accounts when ever you need. The configuration details should be given as follows:
var email = new Email("smtp.gmail.com", "25", "username@gmail.com", "password"); // host, port, username, passwordNote: If the configuration details are given in the server.xml and the user invokes the above constructor, the details given by the user when creating the email object take precedence.
-
The third is a slight variant of the second. 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"; |