org.wso2.mashup.hostobjects.email
Class Email

java.lang.Object
  extended by org.mozilla.javascript.ScriptableObject
      extended by org.wso2.mashup.hostobjects.email.Email
All Implemented Interfaces:
java.io.Serializable, org.mozilla.javascript.ConstProperties, org.mozilla.javascript.debug.DebuggableObject, org.mozilla.javascript.Scriptable

public class Email
extends org.mozilla.javascript.ScriptableObject
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. Notes: The constructor of the Emal object can be called with or without user credentials. If its called with credentials they are used to authenticate the user. If the function is called without credentials the details are taken from the server.xml found under conf directory where the mashup server is located. So if you wish to keep the credentials in server.xml please update it with the needed usernames and passwords. The section that corresponds to this is as follows.

   <EmailConfig>
       <host>smtp.gmail.com</host>
       <port>25</port>
       <username>username@gmail.com</username>
       <password>password</password>
   </EmailConfig>
 eg:
 
     function sendEmail(){
          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.
          email.text = "WSO2 Mashup server 1.0 was Released on 28th January 2008";
          email.send();
     }
 
 
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.mozilla.javascript.ScriptableObject
CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
 
Fields inherited from interface org.mozilla.javascript.Scriptable
NOT_FOUND
 
Constructor Summary
Email()
           
 
Method Summary
 java.lang.String getClassName()
          Return the name of the class.
static org.mozilla.javascript.Scriptable jsConstructor(org.mozilla.javascript.Context cx, java.lang.Object[] args, org.mozilla.javascript.Function ctorObj, boolean inNewExpr)
           The Email Object has three different constructors.
static void jsFunction_addAttachement(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, java.lang.Object[] arguments, org.mozilla.javascript.Function funObj)
           
static void jsFunction_addAttachment(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, java.lang.Object[] arguments, org.mozilla.javascript.Function funObj)
          Add attachments to the mail been sent.
 void jsFunction_send()
          Send the mail out email.send()
 java.lang.String[] jsGet_bcc()
           
 java.lang.String[] jsGet_cc()
           
 java.lang.String jsGet_from()
           
 java.lang.String jsGet_html()
           
 java.lang.String jsGet_subject()
           
 java.lang.String jsGet_text()
           
 java.lang.String[] jsGet_to()
           
 void jsSet_bcc(java.lang.Object bccObject)
          The bcc address that the mail is sent to email.bcc = "keith@wso2.com"; OR var bcc = new Array(); bcc[0] = "jonathan@wso2.com"; bcc[1] = "keith@wso2.com"; email.bcc = bcc;
 void jsSet_cc(java.lang.Object ccObject)
          The cc address that the mail is sent to email.cc = "keith@wso2.com"; OR var cc = new Array(); cc[0] = "jonathan@wso2.com"; cc[1] = "keith@wso2.com"; email.cc = cc;
 void jsSet_from(java.lang.String from)
          The from address to appear in the email email.from = "keith@wso2.com";
 void jsSet_html(java.lang.Object html)
          The body of the email to be sent.
 void jsSet_subject(java.lang.String subject)
          The subject of the mail been sent email.subject = "WSO2 Mashup server 1.0 Released";
 void jsSet_text(java.lang.String text)
          The body text of the mail been sent email.text = "WSO2 Mashup server 1.0 was Released on 28th January 2008";
 void jsSet_to(java.lang.Object toObject)
          The to address that the mail is sent to email.to = "keith@wso2.com"; OR var to = new Array(); to[0] = "jonathan@wso2.com"; to[1] = "keith@wso2.com"; email.to = to;
 
Methods inherited from class org.mozilla.javascript.ScriptableObject
associateValue, callMethod, callMethod, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, deleteProperty, deleteProperty, get, get, getAllIds, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getDefaultValue, getFunctionPrototype, getGetterOrSetter, getIds, getObjectPrototype, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, getTopScopeValue, has, has, hasInstance, hasProperty, hasProperty, isConst, isSealed, put, put, putConst, putConstProperty, putProperty, putProperty, redefineProperty, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setGetterOrSetter, setParentScope, setPrototype
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Email

public Email()
Method Detail

getClassName

public java.lang.String getClassName()
Return the name of the class. This is typically the same name as the constructor. Classes extending ScriptableObject must implement this abstract method.
Specified by:
getClassName in interface org.mozilla.javascript.Scriptable
Specified by:
getClassName in class org.mozilla.javascript.ScriptableObject

jsConstructor

public static org.mozilla.javascript.Scriptable jsConstructor(org.mozilla.javascript.Context cx,
                                                              java.lang.Object[] args,
                                                              org.mozilla.javascript.Function ctorObj,
                                                              boolean inNewExpr)
                                                       throws org.wso2.mashup.MashupFault

The Email Object has three different constructors. Choose one depending on your configuration and your needs. 1. 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(); 2. 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, password 3. 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

Throws:
org.wso2.mashup.MashupFault

jsSet_from

public void jsSet_from(java.lang.String from)
                throws org.wso2.mashup.MashupFault

The from address to appear in the email

 email.from = "keith@wso2.com";
 
Throws:
org.wso2.mashup.MashupFault

jsGet_from

public java.lang.String jsGet_from()
                            throws javax.mail.MessagingException
Throws:
javax.mail.MessagingException

jsGet_to

public java.lang.String[] jsGet_to()
                            throws org.wso2.mashup.MashupFault
Throws:
org.wso2.mashup.MashupFault

jsSet_to

public void jsSet_to(java.lang.Object toObject)
              throws org.wso2.mashup.MashupFault

The to address that the mail is sent to

 email.to = "keith@wso2.com";

 OR

 var to = new Array();
 to[0] = "jonathan@wso2.com";
 to[1] =  "keith@wso2.com";
 email.to = to;
 
Throws:
org.wso2.mashup.MashupFault

jsGet_cc

public java.lang.String[] jsGet_cc()
                            throws org.wso2.mashup.MashupFault
Throws:
org.wso2.mashup.MashupFault

jsSet_cc

public void jsSet_cc(java.lang.Object ccObject)
              throws org.wso2.mashup.MashupFault

The cc address that the mail is sent to

 email.cc = "keith@wso2.com";

 OR

 var cc = new Array();
 cc[0] = "jonathan@wso2.com";
 cc[1] =  "keith@wso2.com";
 email.cc = cc;
 
Throws:
org.wso2.mashup.MashupFault

jsGet_bcc

public java.lang.String[] jsGet_bcc()
                             throws org.wso2.mashup.MashupFault
Throws:
org.wso2.mashup.MashupFault

jsSet_bcc

public void jsSet_bcc(java.lang.Object bccObject)
               throws org.wso2.mashup.MashupFault

The bcc address that the mail is sent to

 email.bcc = "keith@wso2.com";

 OR

 var bcc = new Array();
 bcc[0] = "jonathan@wso2.com";
 bcc[1] =  "keith@wso2.com";
 email.bcc = bcc;
 
Throws:
org.wso2.mashup.MashupFault

jsSet_subject

public void jsSet_subject(java.lang.String subject)
                   throws org.wso2.mashup.MashupFault

The subject of the mail been sent

 email.subject = "WSO2 Mashup server 1.0 Released";
 
Throws:
org.wso2.mashup.MashupFault

jsGet_subject

public java.lang.String jsGet_subject()
                               throws org.wso2.mashup.MashupFault
Throws:
org.wso2.mashup.MashupFault

jsSet_text

public void jsSet_text(java.lang.String text)
                throws org.wso2.mashup.MashupFault

The body text of the mail been sent

 email.text = "WSO2 Mashup server 1.0 was Released on 28th January 2008";
 
Throws:
org.wso2.mashup.MashupFault

jsGet_text

public java.lang.String jsGet_text()

jsSet_html

public void jsSet_html(java.lang.Object html)
                throws org.wso2.mashup.MashupFault

The body of the email to be sent. This function can be used to send HTML mail.

 email.html = "

WSO2 Mashup server 1.0 was Released on 28th January 2008

";  // Setthing the HTML content as a String
                                                   OR
 email.html = 

WSO2 Mashup server 1.0 was Released on 28th January 2008

;     // Setting the HTML content as an XML object
 
Throws:
org.wso2.mashup.MashupFault

jsGet_html

public java.lang.String jsGet_html()

jsFunction_send

public void jsFunction_send()
                     throws org.wso2.mashup.MashupFault

Send the mail out

 email.send()
 
Throws:
org.wso2.mashup.MashupFault

jsFunction_addAttachement

public static void jsFunction_addAttachement(org.mozilla.javascript.Context cx,
                                             org.mozilla.javascript.Scriptable thisObj,
                                             java.lang.Object[] arguments,
                                             org.mozilla.javascript.Function funObj)
                                      throws org.wso2.mashup.MashupFault
Throws:
org.wso2.mashup.MashupFault

jsFunction_addAttachment

public static void jsFunction_addAttachment(org.mozilla.javascript.Context cx,
                                            org.mozilla.javascript.Scriptable thisObj,
                                            java.lang.Object[] arguments,
                                            org.mozilla.javascript.Function funObj)
                                     throws org.wso2.mashup.MashupFault

Add attachments to the mail 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");
 
Throws:
org.wso2.mashup.MashupFault