Email Objects |
Active Web |
An Email object allows you to send an Email using the SMTP protocol (Simple Mail Transfer Protocol).
The script server will use SMTP to connect to the server specified in the server property (on the port if specified) and send the message. For this to work the script server machine must be on a network that has access to an SMTP server.
After the Email object has been created, any of its properties can be changed and it can be sent as often as required by using the send function.
Email objects are of class Email.
Property |
Description |
attachments |
A single string (for multiple attachments separated by commas) or an array of strings defining the files to attach to the Email |
bcc |
A single string (for multiple bcc separated by commas) or an array of strings defining the Email addresses of "blind carbon copy" recipients. |
cc |
A single string (for multiple cc separated by commas) or an array of strings defining the Email addresses of "carbon copy" recipients. |
contentType |
A string defining the mime type of the message. The default is "text/plain". Tip: To send HTML formatted messages change this to "text/html" and you can then put HTML code in the message string. |
error |
An error message If an error has occurred. If no error has occurred then it will be null. The error messages are explained below: property missing error - One of the following properties is either not set or is invalid: from, to, message, server, port & timeout. Unknown Host error - The mail server named in the server property could not be found. SMTP Protocol error - There was a protocol error when communicating with the mail server. Connection error - There was an error when sending the message to the mail server. |
from |
A string defining the Email address of the sender of the message. This will become the "reply to" address for the recipient. |
headerText |
A string containing header text for adding additional header fields. |
message |
A string containing the Email message. |
port |
The port that will be used by the script server to connect to the SMTP server. If this is null then the default is port 25. |
prototype |
A reference to the Object Prototype. This property does not enumerate and can not be deleted but can be changed. |
server |
A string defining the network name of the SMTP mail server that the script server will use to send the message. |
subject |
A string defining the subject of the Email. |
timeout |
The number of milliseconds to wait until the server connection is considered as timed out. If this is not set it will default to 10000 (10 seconds). |
to |
A string defining the Email address of the recipient. |
Function |
Description |
send() |
Causes the Email object to send the Email to the SMTP server using the data contained in its variables. Returns true if there was no error and false if an error occurred. |
This example creates an Email object, sets some of its properties and sends the email. Those properties not set will use the defaults.
var myEmail = new Email();
myEmail.server = “mailserver.elsewhere.com”;
myEmail.from = “me@elsewhere.com”;
myEmail.to = “someone@somewhere.com”;
myEmail.subject = “An Active Web Email”;
myEmail.message = “Hello”;
myEmail.attachments = “c:\afile.txt”;
if (myEmail.send()) {
writeln(“I have sent an Email”);
}
else {
writeln(“There was an error sending the Email: ”+myEmail.error);
}
The Email object always puts the following fields in the header: From, To, cc, Bcc & Subject. The Content-type field is also included if the property is not null. If the headerText property is not null it is then included in the header. This allows you to add additional fields to the header. The RFC822 specification explains how header fields should be formatted.
This example sets the header text of an Email object to send an HTML email.
myEmail.headerText = 'Content-Type: text/html; charset=us-ascii; name=“index.html”\n';
myEmail.headerText += 'Content-Transfer-Encoding: 7bit\n';
myEmail.headerText += 'Content-Disposition: inline; filename=“index.html”\n';
myEmail.headerText += 'Content-Base: http://www.inetAddress.com\n';
myEmail.headerText += 'MIME-Version: 1.0\n';
The Email constructor is used to create new Email objects.
var myEmail = new Email();
A new Email object is created with no properties set.
var myEmail = new Email(server[, port[, from[, to[, bcc[, cc[, subject[, message[, attachments[, timeout]]]]]]]]]);
A new Email object is created using the arguments supplied to set the relevant properties.
Shown below is the Email object prototype chain.
When the constructor is run as a function without the new operator it has exactly the same behaviour as using the new operator.
Email Constructor Properties
Constructor properties are read only (they can not be changed or deleted) and it is not possible to add new properties to the Constructor.
Property |
Description |
prototype |
A reference to the Object Prototype. This property does not enumerate and can not be changed or deleted. |
The Email constructor has no predefined functions.
Topic ID: 150050