org.jaggeryjs.modules.email
Class SenderHostObject

java.lang.Object
  extended by org.mozilla.javascript.ScriptableObject
      extended by org.jaggeryjs.modules.email.SenderHostObject
All Implemented Interfaces:
Serializable, org.mozilla.javascript.ConstProperties, org.mozilla.javascript.debug.DebuggableObject, org.mozilla.javascript.Scriptable

public class SenderHostObject
extends org.mozilla.javascript.ScriptableObject

The sender 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.

smtp.gmail.com 25 username@gmail.com password

 eg:
 

function sendEmail(){ var email = new Sender("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
SenderHostObject()
           
 
Method Summary
 String getClassName()
          Return the name of the class.
static org.mozilla.javascript.Scriptable jsConstructor(org.mozilla.javascript.Context cx, Object[] args, org.mozilla.javascript.Function ctorObj, boolean inNewExpr)
           The Sender Object has three different constructors.
static void jsFunction_addAttachment(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, Object[] arguments, org.mozilla.javascript.Function funObj)
          Add attachments to the mail been sent.
 void jsFunction_send()
          Send the mail out
 String[] jsGet_bcc()
           
 String[] jsGet_cc()
           
 String jsGet_from()
           
 String jsGet_html()
           
 String jsGet_subject()
           
 String jsGet_text()
           
 String[] jsGet_to()
           
 void jsSet_bcc(Object bccObject)
          The bcc address that the mail is sent to
 void jsSet_cc(Object ccObject)
          The cc address that the mail is sent to
 void jsSet_from(String from)
          The from address to appear in the sender
 void jsSet_html(Object html)
          The body of the sender to be sent.
 void jsSet_subject(String subject)
          The subject of the mail been sent
 void jsSet_text(String text)
          The body text of the mail been sent
 void jsSet_to(Object toObject)
          The to address that the mail is sent to
 
Methods inherited from class org.mozilla.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, equivalentValues, get, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getDefaultValue, getFunctionPrototype, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getSlot, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, has, hasInstance, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, put, putConst, putConstProperty, putProperty, putProperty, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setGetterOrSetter, setParentScope, setPrototype, size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SenderHostObject

public SenderHostObject()
Method Detail

getClassName

public 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,
                                                              Object[] args,
                                                              org.mozilla.javascript.Function ctorObj,
                                                              boolean inNewExpr)
                                                       throws org.jaggeryjs.scriptengine.exceptions.ScriptException

The Sender 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 Sender();

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 Sender("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 Sender("smtp.gmail.com", "username@gmail.com", "password"); // host, username, password

Throws:
org.jaggeryjs.scriptengine.exceptions.ScriptException

jsSet_from

public void jsSet_from(String from)
                throws org.jaggeryjs.scriptengine.exceptions.ScriptException

The from address to appear in the sender

 sender.from = "keith@wso2.com";
 

Throws:
org.jaggeryjs.scriptengine.exceptions.ScriptException

jsGet_from

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

jsGet_to

public String[] jsGet_to()
                  throws org.jaggeryjs.scriptengine.exceptions.ScriptException
Throws:
org.jaggeryjs.scriptengine.exceptions.ScriptException

jsSet_to

public void jsSet_to(Object toObject)
              throws org.jaggeryjs.scriptengine.exceptions.ScriptException

The to address that the mail is sent to

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

 OR

 var to = new Array();
 to[0] = "jonathan@wso2.com";
 to[1] =  "keith@wso2.com";
 sender.to = to;
 

Throws:
org.jaggeryjs.scriptengine.exceptions.ScriptException

jsGet_cc

public String[] jsGet_cc()
                  throws org.jaggeryjs.scriptengine.exceptions.ScriptException
Throws:
org.jaggeryjs.scriptengine.exceptions.ScriptException

jsSet_cc

public void jsSet_cc(Object ccObject)
              throws org.jaggeryjs.scriptengine.exceptions.ScriptException

The cc address that the mail is sent to

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

 OR

 var cc = new Array();
 cc[0] = "jonathan@wso2.com";
 cc[1] =  "keith@wso2.com";
 sender.cc = cc;
 

Throws:
org.jaggeryjs.scriptengine.exceptions.ScriptException

jsGet_bcc

public String[] jsGet_bcc()
                   throws org.jaggeryjs.scriptengine.exceptions.ScriptException
Throws:
org.jaggeryjs.scriptengine.exceptions.ScriptException

jsSet_bcc

public void jsSet_bcc(Object bccObject)
               throws org.jaggeryjs.scriptengine.exceptions.ScriptException

The bcc address that the mail is sent to

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

 OR

 var bcc = new Array();
 bcc[0] = "jonathan@wso2.com";
 bcc[1] =  "keith@wso2.com";
 sender.bcc = bcc;
 

Throws:
org.jaggeryjs.scriptengine.exceptions.ScriptException

jsSet_subject

public void jsSet_subject(String subject)
                   throws org.jaggeryjs.scriptengine.exceptions.ScriptException

The subject of the mail been sent

 sender.subject = "WSO2 Mashup server 1.0 Released";
 

Throws:
org.jaggeryjs.scriptengine.exceptions.ScriptException

jsGet_subject

public String jsGet_subject()
                     throws org.jaggeryjs.scriptengine.exceptions.ScriptException
Throws:
org.jaggeryjs.scriptengine.exceptions.ScriptException

jsSet_text

public void jsSet_text(String text)
                throws org.jaggeryjs.scriptengine.exceptions.ScriptException

The body text of the mail been sent

 sender.text = "WSO2 Mashup server 1.0 was Released on 28th January 2008";
 

Throws:
org.jaggeryjs.scriptengine.exceptions.ScriptException

jsGet_text

public String jsGet_text()

jsSet_html

public void jsSet_html(Object html)
                throws org.jaggeryjs.scriptengine.exceptions.ScriptException

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

 sender.html = "

WSO2 Mashup server 1.0 was Released on 28th January 2008

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

WSO2 Mashup server 1.0 was Released on 28th January 2008

; // Setting the HTML content as an XML object

Throws:
org.jaggeryjs.scriptengine.exceptions.ScriptException

jsGet_html

public String jsGet_html()

jsFunction_send

public void jsFunction_send()
                     throws org.jaggeryjs.scriptengine.exceptions.ScriptException

Send the mail out

 sender.send()
 

Throws:
org.jaggeryjs.scriptengine.exceptions.ScriptException

jsFunction_addAttachment

public static void jsFunction_addAttachment(org.mozilla.javascript.Context cx,
                                            org.mozilla.javascript.Scriptable thisObj,
                                            Object[] arguments,
                                            org.mozilla.javascript.Function funObj)
                                     throws org.jaggeryjs.scriptengine.exceptions.ScriptException

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
 sender.addAttachement(file, "temp.txt");
 

Throws:
org.jaggeryjs.scriptengine.exceptions.ScriptException


Copyright © 2015 WSO2 Inc. All rights reserved.