OpenWGA 7.7 - TMLScript reference


Object:

Mail

Description The "Mail" object provides comfortable creation and sending of SMTP E-Mails. It either uses the Mail Configuration of the OpenWGA server or some custom SMTP server configured on object creation.

The object represents a mail whose usual fields like to, subject, body etc. can be filled with data. You can also add attachment files either by specifying their URL or a file in file system.

When the mail is finished it can be either sent or returned as native mail object for further, more specific operations. A single mail can be used to send the mail data multiple times. You can also modify the data between sending calls if you need to send multiple mails with slightly differing data.



The Mail object is not "thread safe", i.e. one instance of it cannot be reused across requests or used on multiple requests/scripts simultaneously.
Retrieval WGA.createMail()
Allowed in script types
  • WebTML pages and normal WebTML actions
  • Master actions
  • TMLScript tasks in jobs
  • Content type events
    portletevent
Properties and methods
Name Purpose
addAttachment(file)
addAttachment(document, fileName [, altFileName])
addAttachment(inputStream, fileName)
Add an attachment to the mail, either from a file, a document attachment or a Java input stream
addAttachmentURL(url [, alternateFileName]) Adds an attachment to the mail by URL
bcc The list of "blind copy" addresses that this mail should be sent to
body The body content of the mail
cc The list of "copy to" addresses that this mail is sent to
encodeText Controls if subject and body of the mail should be encoded on send
from The sender address of the mail to send
getAttachmentURLs() Returns the URLs of resources that will be attached on the mail to send
mimeType The mime type as which the body content of the mail should be intepreted
prepareMessage() Creates a Java object javax.mail.internet.MimeMessage from the configured settings
replyTo A "reply to" address for the email to send
send([message]) Sends the created E-Mail
setBcc(address) Sets a single "blind copy to" address or multiple addresses that this mail will be sent to as blind copy.
setCc(address) Sets a single "copy to" address or a list of addresses that this E-Mail will be sent to as mail copy
setFrom(address[, name]) Set the sender address of the mail to send
setTo(address) Sets a single or multiple recipient E-Mail address(es) that this mail will be sent to
subject The subject of the mail to send
to The list of recipients of the mail to send
Examples

This example creates a mail object, initializes it with the neccessary data from a WebTML form and sends it. Note the mime type "text/html" that is set.  In that case the body content should also be HTML code.

var mail = WGA.createMail();
mail.setSubject ( this.tmlform.field("subject") );
mail.setBody( this.tmlform.field("mailbody") );
mail.setTo( this.tmlform.field("to") );
mail.setFrom( "some@mailaddress.com" );
mail.setMimeType("text/html");

mail.addAttachmentURL("http://www.xyz.com/package.zip");

mail.send();