Fork me on GitHub Fork me on GitHub

Sender


<%

	var content = request.getParameter("cont");
	var to = request.getParameter("to");
	var subject = request.getParameter("sub");
	
	var email = require('email');
	var sender = new email.Sender("smtp.gmail.com", "25", "username", "password", "tls");
	
	sender.from = "";
	sender.to = to;
	sender.cc = "";
	sender.bcc = "";
	sender.subject = subject;
	sender.text = content;
	sender.send();
	
	print("email successfully sent to " + to);
%>

Overview

The Sender Object allows users to send out email from their apps.


Members

Member Type Description
fromString
sender.from = "madhuka@wso2.com"; 
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.
to String or Array
sender.to = "nuwan@wso2.com"; 
var to = new Array();
to[0] = "nuwan@wso2.com";
to[1] = "teague@wso2.com";
sender.to = 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 above.)

cc String or Array
sender.cc = "madhuka@wso2.com"; 
var cc = new Array();
cc[0] = "nuwan@wso2.com";
cc[1] = "teague@wso2.com";
sender.cc= 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 above.)

bccString or Array
sender.bcc = "jhon@wso2.com";
var bcc = new Array();
bcc[0] = "jonathan@wso2.com";
bcc[1] = "nuwan@wso2.com";
sender.bcc = 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.)

subjectString
sender.subject = "WSO2 Jaggery on Released";
An optional property to set the subject of the email to be sent.
textString
sender.text = "Jaggery goes on live from 2012"; 
An optional property to set the body text of the email to be sent.
htmlString or XML Object
sender.html = "<h1>Jaggery was Released on January 2012</h1>";
// Setthing the HTML content as a String 
sender.html = "<h1>Jaggery was Released on January 2012</h1>";
// Setting the HTML content as an XML object 

An optional property to set the body of the email to be sent. This function can be used to send HTML mail.

Operations

Operations Returns Description
Sender()None
var sender = new email.Sender("smtp.example.com", "25", "username@example.com", "password"); 
var sender = new email.Sender("smtp.gmail.com", "25", "username@gmail.com", "password", "tls");

Adding "tls" as the fifth argument will enable TLS for the communication

addAttachment([String filePath] [FileHostObject file]) None

The current state of the object, which can be one of the following values:

  • 0: The object has not been initialized by calling the open() method.
  • 1: The object has been initialized successfully, but the send() method has not been called.
  • 2: The request is pending
  • 3: The request is partially complete (some data has been received, and may be available in the responseText property.
  • 4: The request is complete, all data has been received.

Of these, typically only the last (readyState == 4) is used.

send() NoneUsed to send the email.