DOCUMENTS 5 - PortalScripting API
Public Member Functions | List of all members
Email Class Reference

The Email class allows to create and send an email. More...

Public Member Functions

boolean addAttachment (Var attachment, String sourceFilePath)
 Add an attachment to the email. More...
 
Email Email (String to, String from, String subject, String body, String cc, String bcc, Date sendingTime, boolean deleteAfterSending)
 Create a new instance of the Email class. More...
 
String getLastError ()
 Get the description of the last error that occurred. More...
 
boolean send ()
 Send the email to recipients. More...
 
boolean setBCC (String bcc)
 Set blind carbon-copy recipients of the email. More...
 
boolean setBody (String body)
 Set the content of the email. More...
 
boolean setCC (String cc)
 Set carbon-copy recipients of the email. More...
 
boolean setDeleteAfterSending (boolean deleteAfterSending)
 Decide on whether the email is to be deleted after successful sending. More...
 
boolean setFrom (String from)
 Set the sender's email address. More...
 
boolean setSendingTime (Date sendingTime)
 Set sending time of the email. More...
 
boolean setSubject (String subject)
 Set the subject of the email. More...
 
boolean setTo (String to)
 Set the primary recipients of the email. More...
 

Detailed Description

The Email class allows to create and send an email.

All the email settings for the principal (such as SMTP server and authentication) are used when sending an email.

Since
DOCUMENTS 4.0d
Example:
var mail = new Email("receiver@domain.de", "sender@domain.de", "Test", "This is a test email.");
mail.addAttachment("log.txt", "C:\\tmp\\changelog.txt");
mail.setBCC("somebody1@domain.de,somebody2@domain.com");
mail.setDeleteAfterSending(true);
if (!mail.send())
util.out(mail.getLastError());

Constructor & Destructor Documentation

◆ Email()

Email Email::Email ( String  to,
String  from,
String  subject,
String  body,
String  cc,
String  bcc,
Date  sendingTime,
boolean  deleteAfterSending 
)

Create a new instance of the Email class.

In case of multiple recipients for the parameters to, cc or bcc, the individual email addresses are to be separated by a comma (,). It is not allowed to send an email without any primary recipients specified by the parameter to. To send a HTML email the body must begin with the <HTML> tag. Emails in following cases are stored in the folder Administration > Sent eMails in the DOCUMENTS Manager:

  • They are to be sent in the future (specified by sendingTime);
  • Sending them failed;
  • The parameter deleteAfterSending is set to false.
Parameters
toString value containing the email addresses of primary recipients.
fromOptional string value containing the sender's email address. If no sender is specified, the default sender for the principal is used.
subjectOptional string value containing the subject of the email.
bodyOptional string value containing the content of the email.
ccOptional string value containing the email addresses of carbon-copy recipients (appearing in the header of the email).
bccOptional string value containing the email addresses of blind carbon-copy recipients (remaining invisible to other recipients).
sendingTimeOptional Date object specifying when the email is to be sent. If sending time is not specified, the email will be sent immediately by calling send().
deleteAfterSendingOptional flag indicating whether the email is to be deleted after successful sending. The default value is true.
Since
DOCUMENTS 4.0d

Member Function Documentation

◆ addAttachment()

boolean Email::addAttachment ( Var  attachment,
String  sourceFilePath 
)

Add an attachment to the email.

Parameters
attachmentDocument object or string value containing the attachment name of the Email.
sourceFilePathOptional string value containing the path of the file to be attached and stored on the server's filesystem in case the first parameter is a string specifying the attachment name. You may only delete this file after calling the function send().
Note: This Parameter is ignored in case the first parameter is a Document object.
Returns
true if successful, false in case of any error
Since
DOCUMENTS 4.0d
Example:
var mail = new Email("receiver@domain.de", "sender@domain.de", "Test", "This is a test.");
if (!mail.addAttachment("log.txt", "C:\\tmp\\changelog.txt"))
util.out(mail.getLastError());

◆ getLastError()

String Email::getLastError ( )

Get the description of the last error that occurred.

Returns
Text of the last error as String
Since
DOCUMENTS 4.0d

◆ send()

boolean Email::send ( )

Send the email to recipients.

Returns
true if successful, false in case of any error
Since
DOCUMENTS 4.0d
Example:
var mail = new Email("receiver@domain.de");
mail.setSubject("Test");
mail.setBody("This is a test mail.");
if (!mail.send())
util.out(mail.getLastError());

◆ setBCC()

boolean Email::setBCC ( String  bcc)

Set blind carbon-copy recipients of the email.

Parameters
bccString containing the email addresses of blind carbon-copy recipients.
Returns
true if successful, false in case of any error
Since
DOCUMENTS 4.0d

◆ setBody()

boolean Email::setBody ( String  body)

Set the content of the email.

Parameters
bodyString containing the content of the email.
Note: To send a HTML email the body must begin with the <HTML> tag.
Returns
true if successful, false in case of any error
Since
DOCUMENTS 4.0d
Example:
var mail = new Email("receiver@domain.de");
mail.setSubject("Test");
mail.setBody("<HTML>This is a &#x3c;HTML&#x3e; mail.");
if (!mail.send())
util.out(mail.getLastError());

◆ setCC()

boolean Email::setCC ( String  cc)

Set carbon-copy recipients of the email.

Parameters
ccString containing the email addresses of carbon-copy recipients.
Returns
true if successful, false in case of any error
Since
DOCUMENTS 4.0d

◆ setDeleteAfterSending()

boolean Email::setDeleteAfterSending ( boolean  deleteAfterSending)

Decide on whether the email is to be deleted after successful sending.

Parameters
deleteAfterSendingboolean value indicating whether the email is to be deleted after successful sending.
Returns
true if successful, false in case of any error
Since
DOCUMENTS 4.0d

◆ setFrom()

boolean Email::setFrom ( String  from)

Set the sender's email address.

Parameters
fromString containing the sender's email address.
Returns
true if successful, false in case of any error
Since
DOCUMENTS 4.0d

◆ setSendingTime()

boolean Email::setSendingTime ( Date  sendingTime)

Set sending time of the email.

Parameters
sendingTimeDate object representing the sending time.
Returns
true if successful, false in case of any error
Since
DOCUMENTS 4.0d
Example:
var mail = new Email("receiver@domain.de", "sender@domain.de", "Test", "This is a test.");
var actDate = new Date();
var newDate = context.addTimeInterval(actDate, 2, "days", false);
mail.setSendingTime(newDate);

◆ setSubject()

boolean Email::setSubject ( String  subject)

Set the subject of the email.

Parameters
subjectString containing the desired subject of the email.
Returns
true if successful, false in case of any error
Since
DOCUMENTS 4.0d

◆ setTo()

boolean Email::setTo ( String  to)

Set the primary recipients of the email.

Parameters
toString containing the email addresses of primary recipients.
Returns
true if successful, false in case of any error
Since
DOCUMENTS 4.0d

This documentation refers DOCUMENTS 5.0e (2105).
Created at 11-09-2019. - © 1998-2019 otris software AG, Königswall 21, D-44137 Dortmund. support@otris.de