Skip to main content

Email

Send an email, using SMTP settings defined at application level/globally​

Syntax

utils.sendEmail(from, to, cc, bcc, subject, body, isHtmlContent, returnReceipt, zipFiles, deleteFilesAfterSending, dirId, fileName, filesToAttach)

Details

ArgumentDescription
from(optional, can be null) a string representing the email address to use as the "from address" to send the email
toa string composed of one or more email addresses, separated by a comma (,)
cccarbon copy addresses - a string composed of one or more email addresses, separated by a comma (,)
bcchidden addresses - a string composed of one or more email addresses, separated by a comma (,)
subjecta string representing the email title
bodythe email body content
isHtmlContenta boolean flag used to define if the body content is in HTML format or not
returnReceipta boolean flag used to request a return receipt to the destinators
zipFilesa boolean flag used to compress all files to attach in a unique zip file and send it, in order to reduce the email size
deleteFilesAfterSendinga boolean flag used to optionally delete files to attach, after sending the email
dirIdoptional dir id used to save the message also to the server file system
fileNameoptional file name required in case the dir id has been specified; the message will be save in eml format on the file system
filesToAttacha list of files to attach, separated by a comma; use [] to notinclude files; each file must include the absolute path

This method will fire an exception if the email has NOT been sent correctly (e.g. attachment file not found).

Example without attachments:

utils.sendEmail(
"fromemailaddress@mydomain.com", // from address
"toemailaddress@domain.com", // to address, can be a list of email addresses, separated by a comma (,)
null, // carbon copy
null, // blank carbon copy
"email title", // subject
"email body", // it can be plain text or HTML formatted text
true, // isHtmlContent, false to set plain text
false, // returnReceipt
false, // zipFiles, in case of attachments
false, // deleteFilesAfterSending, in case of attachments
null, // dirId, in case of attachments
null, // fileName, in case of attachments
null, // filesToAttach, in case of attachments
);

Example with attachments:

var myDirId = ...; // directory id, representing the base dir where files have been stored; defined in Administration -> Directories
var filesToAttach = ["myfile1.txt", "myfile2.pdf", ...];

utils.sendEmail(
"fromemailaddress@mydomain.com", // from address
"toemailaddress@domain.com", // to address, can be a list of email addresses, separated by a comma (,)
null, // carbon copy
null, // blank carbon copy
"email title", // subject
"email body", // it can be plain text or HTML formatted text
true, // isHtmlContent, false to set plain text
false, // returnReceipt
false, // zipFiles, in case of attachments
false, // deleteFilesAfterSending, in case of attachments
myDirId, // dirId, in case of attachments
null, // fileName, in case of attachments
[], // filesToAttach, in case of attachments
);

Important note: in order to use this feature, you have also to define a few global/application parameters:

MAIL_SMTP_HOST
MAIL_SMTP_PORT

These are optional:

MAIL_SMTP_PROTOCOL
MAIL_SMTP_USE_TLS
MAIL_SMTP_USERNAME
MAIL_SMTP_PASSWORD

Send an email, using SMTP settings defined at application level/globally​

Syntax

utils.sendEmail(smtpHost, smtpPort, useTLS, protocol, smtpUsername, smtpPassword, from, to, subject, body, isHtmlContent, zipFiles, deleteFilesAfterSending, filesToAttach)

Details

ArgumentDescription
smtpHostSMPT host name to use
smtpPortSMTP port
useTLSflag to use (Y/N) to enable TLS
protocolProtocol to use (e.g. smtp vs smtps)
smtpUsernameSMTP username to use to authetication to the SMTP server
smtpPasswordSMTP password to use to authetication to the SMTP server
from(optional, can be null) a string representing the email address to use as the "from address" to send the email
toa string composed of one or more email addresses, separated by a comma (,)
cccarbon copy addresses - a string composed of one or more email addresses, separated by a comma (,)
bcchidden addresses - a string composed of one or more email addresses, separated by a comma (,)
subjecta string representing the email title
bodythe email body content
isHtmlContenta boolean flag used to define if the body content is in HTML format or not
returnReceipta boolean flag used to request a return receipt to the destinators
zipFilesa boolean flag used to compress all files to attach in a unique zip file and send it, in order to reduce the email size
deleteFilesAfterSendinga boolean flag used to optionally delete files to attach, after sending the email
filesToAttacha list of files to attach, separated by a comma; use [] to notinclude files; each file must include the absolute path

This method will fire an exception if the email has NOT been sent correctly (e.g. attachment file not found).

Send an email message to a user​

Syntax

utils.sendAlertEmailWithConversation(from, subject, message, destinations, priority, isHtmlContent, returnReceipt, conversationId, messageTag, filesToAttach)

Details

ArgumentDescription
fromusername to use to send the message; can be null, if not specified, it will be automatically filled with the current logged user, whose email address must be defined in the user detail form
subjectemail title
messagemessage to send; it can be expressed in HTML format
destinationslist of usernames who will receive the alert; they must be separated by a comma (,); for each username specified, its email address must be defined in the user detail form
prioritypriority to use for the messages to show to a specific user: messages having a higher priority will be showed at the top of the list; it can be null; if not specified, it will be set to "normal"; allowed values: 0 (minor), 1, (normal), 2 (high)
conversationIdconversation id used to identify a chain of messages; optional: if not specified, each message represents the first and last message in the convo
messageTagoptional hidden text to add to the message and used to search for specific messages stored in the message history
filesToAttachlist of files, expressed with an absolute path.

Note: in order to use this feature, you have first to define an application parameters named "SHOW_ALERT_MENU_ITEM" to "Y", otherwise these messages cannot be showed on the client side.

Note: in order to send email, additional application/common parameters must be defined:

MAIL_SMTP_HOST
MAIL_SMTP_PORT

These are optional:

MAIL_SMTP_PROTOCOL
MAIL_SMTP_USE_TLS
MAIL_SMTP_USERNAME
MAIL_SMTP_PASSWORD

Send an email message to a user​

Syntax

utils.sendAlertEmailWithEmailAddressesWithConversation(from, subject, message, destinations, priority, isHtmlContent, returnReceipt, conversationId, messageTag, dirId, fileName, filesToAttach)

Details

ArgumentDescription
fromemail address to use to send the message; can be null, if not specified, it will be automatically filled with the email address of the current logged user (defined in the user detail form)
subjectemail title
messagemessage to send; it can be expressed in HTML format
destinationslist of email addresses who will receive the alert; they must be separated by a comma (,)
prioritypriority to use for the messages to show to a specific user: messages having a higher priority will be showed at the top of the list; it can be null; if not specified, it will be set to "normal"; allowed values: 0 (minor), 1, (normal), 2 (high)
conversationIdconversation id used to identify a chain of messages; optional: if not specified, each message represents the first and last message in the convo
messageTagoptional hidden text to add to the message and used to search for specific messages stored in the message history
filesToAttachlist of files, expressed with an absolute path.

Note: in order to use this feature, you have first to define an application parameters named "SHOW_ALERT_MENU_ITEM" to "Y", otherwise these messages cannot be showed on the client side.

Note: in order to send email, additional application/common parameters must be defined:

MAIL_SMTP_HOST
MAIL_SMTP_PORT

These are optional:

MAIL_SMTP_PROTOCOL
MAIL_SMTP_USE_TLS
MAIL_SMTP_USERNAME
MAIL_SMTP_PASSWORD

Send an email message to a user​

Syntax

utils.sendAlertEmailFromTemplate(String from,Number templateId,String destinations, String carbonCopy, String blindCarbonCopy, String priority,boolean isHtmlContent,Map jsObj,Long dirId,String fileName, String... filesToAttach)

Details

ArgumentDescription
fromusername to use to send the message; can be null, if not specified, it will be automatically filled with the current logged user, whose email address must be defined in the user detail form; it can be overridden by the template "from" field
templateIdid of the template previously defined, used to set subject and body; optionally, the template can be optionally used to set from, to, cc, receipt flag too
destinationslist of usernames who will receive the alert; they must be separated by a comma (,); for each username specified, its email address must be defined in the user detail form; it can be overridden by the template "to" field
carbonCopyoptional argument used to specify a separated list (by comma) of email addresses which will receive the email message in carbon copy
blindCarbonCopyoptional argument used to specify a separated list (by comma) of email addresses which will receive the email message in blind carbon copy
prioritypriority to use for the messages to show to a specific user: messages having a higher priority will be showed at the top of the list; it can be null; if not specified, it will be set to "normal"; allowed values: 0 (minor), 1, (normal), 2 (high)
isHtmlContentflag used to specify if the message text is formatted in HTML or plain text
jsObjjavascript record which substitute the variables in the template previously defined
dirIdoptional dir id used to save the message also to the server file system
fileNameoptional file name required in case the dir id has been specified; the message will be save in eml format on the file system
filesToAttachlist of files, expressed with an absolute path.

Note: in order to use this feature, you have first to define an application parameters named "SHOW_ALERT_MENU_ITEM" to "Y", otherwise these messages cannot be showed on the client side.

Example without attachments:

var templateId = ...; // the template id defined in UI -> Templates

// suppose you template text is something like:
// "Hi :NAME <br/>Pleased to meet you!"
// then there is a :NAME variable to fill in here:
var templateObj = \{
name: "Hohn Doe"
\};

utils.sendAlertEmailFromTemplate(
"fromemailaddress@mydomain.com", // from address
templateId,
"toemailaddress@domain.com", // to address, can be a list of email addresses, separated by a comma (,)
null, // carbon copy
null, // blank carbon copy
null, // priority
true, // isHtmlContent, false to set plain text
templateObj,
null, // dirId, in case of attachments
null, // fileName, in case of attachments
null, // filesToAttach, in case of attachments
);

Note: in order to send email, additional application/common parameters must be defined:

MAIL_SMTP_HOST
MAIL_SMTP_PORT

These are optional:

MAIL_SMTP_PROTOCOL
MAIL_SMTP_USE_TLS
MAIL_SMTP_USERNAME
MAIL_SMTP_PASSWORD

Send an email message to a user​

Syntax

utils.sendAlertEmailFromTemplateWithEmailAddresses(String from, Number templateId, String destinations, String priority, boolean isHtmlContent, NativeObject jsObj, dirId, fileName, filesToAttach)

Details

ArgumentDescription
fromusername to use to send the message; can be null, if not specified, it will be automatically filled with the current logged user, whose email address must be defined in the user detail form; it can be overridden by the template "from" field
templateIdid of the template previously defined, used to set subject and body; optionally, the template can be optionally used to set from, to, cc, receipt flag too
destinationslist of usernames who will receive the alert; they must be separated by a comma (,); for each username specified, its email address must be defined in the user detail form; it can be overridden by the template "to" field
prioritypriority to use for the messages to show to a specific user: messages having a higher priority will be showed at the top of the list; it can be null; if not specified, it will be set to "normal"; allowed values: 0 (minor), 1, (normal), 2 (high)
jsObjjavascript record which substitute the variables in the template previously defined
conversationIdconversation id used to identify a chain of messages; optional: if not specified, each message represents the first and last message in the convo
messageTagoptional hidden text to add to the message and used to search for specific messages stored in the message history
filesToAttachlist of files, expressed with an absolute path.

Note: in order to use this feature, you have first to define an application parameters named "SHOW_ALERT_MENU_ITEM" to "Y", otherwise these messages cannot be showed on the client side.

Note: in order to send email, additional application/common parameters must be defined:

MAIL_SMTP_HOST
MAIL_SMTP_PORT

These are optional:

MAIL_SMTP_PROTOCOL
MAIL_SMTP_USE_TLS
MAIL_SMTP_USERNAME
MAIL_SMTP_PASSWORD

Send an email message to a user​

Syntax

utils.sendAlertEmailFromTemplateWithEmailAddressesWithSMTPSettings(String from, Number templateId, String destinations, String priority, boolean isHtmlContent, NativeObject jsObj, String smtpHost,String smtpPort,String protocol,String smtpUsername,String smtpPassword,String useTLS, dirId, fileName, filesToAttach)

Details

ArgumentDescription
fromusername to use to send the message; can be null, if not specified, it will be automatically filled with the current logged user, whose email address must be defined in the user detail form; it can be overridden by the template "from" field
templateIdid of the template previously defined, used to set subject and body; optionally, the template can be optionally used to set from, to, cc, receipt flag too
destinationslist of usernames who will receive the alert; they must be separated by a comma (,); for each username specified, its email address must be defined in the user detail form; it can be overridden by the template "to" field
prioritypriority to use for the messages to show to a specific user: messages having a higher priority will be showed at the top of the list; it can be null; if not specified, it will be set to "normal"; allowed values: 0 (minor), 1, (normal), 2 (high)
jsObjjavascript record which substitute the variables in the template previously defined
smtpXXX-SMTP settings, required to connect to an SMTP server
ArgumentDescription
dirIdoptional dir id used to save the message also to the server file system
fileNameoptional file name required in case the dir id has been specified; the message will be save in eml format on the file system
filesToAttachlist of files, expressed with an absolute path

Note: in order to use this feature, you have first to define an application parameters named "SHOW_ALERT_MENU_ITEM" to "Y", otherwise these messages cannot be showed on the client side.

Note: in order to send email, additional application/common parameters must be defined:

MAIL_SMTP_HOST
MAIL_SMTP_PORT

These are optional:

MAIL_SMTP_PROTOCOL
MAIL_SMTP_USE_TLS
MAIL_SMTP_USERNAME
MAIL_SMTP_PASSWORD

Send an email message to a user​

Syntax

utils.sendAlertEmailFromTemplateWithConversation(String from, Number templateId, String destinations, String priority, boolean isHtmlContent, NativeObject jsObj, conversationId, messageTag, dirId, fileName, filesToAttach)

Details

ArgumentDescription
fromusername to use to send the message; can be null, if not specified, it will be automatically filled with the current logged user, whose email address must be defined in the user detail form; it can be overridden by the template "from" field
templateIdid of the template previously defined, used to set subject and body; optionally, the template can be optionally used to set from, to, cc, receipt flag too
destinationslist of usernames who will receive the alert; they must be separated by a comma (,); for each username specified, its email address must be defined in the user detail form; it can be overridden by the template "to" field
prioritypriority to use for the messages to show to a specific user: messages having a higher priority will be showed at the top of the list; it can be null; if not specified, it will be set to "normal"; allowed values: 0 (minor), 1, (normal), 2 (high)
jsObjjavascript record which substitute the variables in the template previously defined
conversationIdconversation id used to identify a chain of messages; optional: if not specified, each message represents the first and last message in the convo
messageTagoptional hidden text to add to the message and used to search for specific messages stored in the message history
filesToAttachlist of files, expressed with an absolute path.

Note: in order to use this feature, you have first to define an application parameters named "SHOW_ALERT_MENU_ITEM" to "Y", otherwise these messages cannot be showed on the client side.

Note: in order to send email, additional application/common parameters must be defined:

MAIL_SMTP_HOST
MAIL_SMTP_PORT

These are optional:

MAIL_SMTP_PROTOCOL
MAIL_SMTP_USE_TLS
MAIL_SMTP_USERNAME
MAIL_SMTP_PASSWORD

Send an email message to a user​

Syntax

utils.sendAlertEmailFromTemplateWithEmailAddressesWithConversationAndSMTPSettings(String from, Number templateId, String destinations, String priority, boolean isHtmlContent, NativeObject jsObj, conversationId, messageTag, String smtpHost,String smtpPort,String protocol,String smtpUsername,String smtpPassword,String useTLS, dirId, fileName, filesToAttach)

Details

ArgumentDescription
fromemail address to use to send the message; can be null, if not specified, it will be automatically filled with the email address of the current logged user (defined in the user detail form); it can be overridden by the template "from" field
templateIdid of the template previously defined, used to set subject and body; optionally, the template can be optionally used to set from, to, cc, receipt flag too
destinationslist of email addresses who will receive the alert; they must be separated by a comma (,); it can be overridden by the template "to" field
prioritypriority to use for the messages to show to a specific user: messages having a higher priority will be showed at the top of the list; it can be null; if not specified, it will be set to "normal"; allowed values: 0 (minor), 1, (normal), 2 (high).
isHtmlContentflag used to specify if the message text is formatted in HTML or plain text
jsObjjavascript record which substitute the variables in the template previously defined
conversationIdconversation id used to identify a chain of messages; optional: if not specified, each message represents the first and last message in the convo
messageTagoptional hidden text to add to the message and used to search for specific messages stored in the message history
smtpXXXparameters needed to connect to an SMTP server
dirIdoptional dir id used to save the message also to the server file system
fileNameoptional file name required in case the dir id has been specified; the message will be save in eml format on the file system
filesToAttachlist of files, expressed with an absolute path.

Note: in order to use this feature, you have first to define an application parameters named "SHOW_ALERT_MENU_ITEM" to "Y", otherwise these messages cannot be showed on the client side.

Note: in order to send email, additional application/common parameters must be defined:

MAIL_SMTP_HOST
MAIL_SMTP_PORT

These are optional:

MAIL_SMTP_PROTOCOL
MAIL_SMTP_USE_TLS
MAIL_SMTP_USERNAME
MAIL_SMTP_PASSWORD

Send an email message to a user​

Syntax

utils.sendAlertEmailFromTemplateWithEmailAddressesWithConversation(String from, Number templateId, String destinations, String priority, boolean isHtmlContent, NativeObject jsObj, conversationId, messageTag, dirId, fileName, filesToAttach)

Details

ArgumentDescription
fromemail address to use to send the message; can be null, if not specified, it will be automatically filled with the email address of the current logged user (defined in the user detail form); it can be overridden by the template "from" field
templateIdid of the template previously defined, used to set subject and body; optionally, the template can be optionally used to set from, to, cc, receipt flag too
destinationslist of email addresses who will receive the alert; they must be separated by a comma (,); it can be overridden by the template "to" field
prioritypriority to use for the messages to show to a specific user: messages having a higher priority will be showed at the top of the list; it can be null; if not specified, it will be set to "normal"; allowed values: 0 (minor), 1, (normal), 2 (high).
jsObjjavascript record which substitute the variables in the template previously defined
conversationIdconversation id used to identify a chain of messages; optional: if not specified, each message represents the first and last message in the convo
messageTagoptional hidden text to add to the message and used to search for specific messages stored in the message history
dirIdoptional dir id used to save the message also to the server file system
fileNameoptional file name required in case the dir id has been specified; the message will be save in eml format on the file system
filesToAttachlist of files, expressed with an absolute path.

Note: in order to use this feature, you have first to define an application parameters named "SHOW_ALERT_MENU_ITEM" to "Y", otherwise these messages cannot be showed on the client side.

Note: in order to send email, additional application/common parameters must be defined:

MAIL_SMTP_HOST
MAIL_SMTP_PORT

These are optional:

MAIL_SMTP_PROTOCOL
MAIL_SMTP_USE_TLS
MAIL_SMTP_USERNAME
MAIL_SMTP_PASSWORD

create an URL which can be invoked later from another client ​

(e.g. from an email message as a link) and which will be accepted by Platform, since it contains an authentication token; this URL can be used to invoke a server-side javascript action identified by the specific action id. The URL will show the approve.jsp web page containing the Accept/Reject buttons used to confirm or deny an action invoked when pressing the related button.

Syntax

var url = createAllowedUrl(baseUrl, actionId, aName, aValue, rName, rValue, params, expirationDays, maxTimes, message);

Details

ArgumentDescription
baseUrlbase URL to pass, related to the host name and web context; it will represent the first part of the final URL (e.g. http://host:port/platform/)
actionIdaction identifier to execute when pressing the Accept/Reject button on the web page opened when clicking of the returning URL
aNameparameter name related to the accept event, i.e. parameter passed to the js action when pressing the Accept button
aValueparameter value related to the accept event, i.e. parameter value passed to the js action when pressing the Accept button
rNameparameter name related to the reject event, i.e. parameter passed to the js action when pressing the Reject button
rValueparameter name related to the accept event, i.e. parameter value passed to the js action when pressing the Reject button
paramsadditional parameters to pass to the js action, for instance to identify a specific record to work with
expirationDaysoptional parameter (can be set to 0); if set, it represents the maximum number of days the URL is valid, starting from the URL creation date
maxTimesit represents the maximum number of times the URL can be used before it expires
messagetext to show on the approve.jsp web page, just above the Accept/Reject buttons.

Read a list of messages from the email server ​

Syntax

var emailMessages = utils.getEmails(server, port, username, password, protocol, useTLS, maxMessagesToRead, notReadFilter, startDateFilter, fromAddressFilter, subjectFilter, bodyFilter, withAttachments, attachmentsPath, folderName, moveToFolderOnceRead, setAsSeen, deleteEmailWhenRead, debug);

Details

server -server host
port - server port (e.g. 995)
username - username to use when accessing the email server
password - password to use when accessing the email server
protocol - protocol to use when connecting to the email server (e.g. imap, imaps, pop, pops)
useTLS flag used to enabled the TLS mode
maxMessagesToRead - maximum number of messages to read
ArgumentDescription
notReadFilterflag used to filter only messages not read yet
startSendDateFilter - optional parameter; if not null, messages to read will be filtered by sendingdateonly the ones next or equal to this date wil be returned
fromAddressFilter - optional parameter; if not null, messages to read will be filtered by the "from address" specified
subjectFilter - optional parameter; if not null, messages to read will be filtered and only the ones containing this value in their object will be returned
bodyFilter - optional parameter; if not null, messages to read will be filtered and only the ones containing this value in their body content will be returned
withAttachments - optional parameter; if not null, messages to read will be filtered and only the ones having at least one attachment will be returned
attachmentsPath - absolute path where saving attachments
folderName - folder to read; e.g. INBOX; if not specified, it will be set to INBOX
moveToFolderOnceRead - move to the specified folder each message, once read; can be null
setAsSeen - flag used to mark as "SEEN" a message just read
ArgumentDescription
deleteEmailWhenReadflag used to delete the email message once read
debugflag used to debug the communication with the server
emailMessages - return valuelist of messages read from the mail box

Attributes contained in each message of the list:

AttributeDescription
idemail identifier, used to delete an email message later
fromfrom email address
toto email address
messageemail body
subjectemail subject
mimeTypee.g. "text/plain" or "text/html"
attachmentslist of absolute paths (strings) where the attachments have been saved
sendDatemessage sending date (since 5.0.1 version)
receiveDatemessage receiving date (since 5.0.1 version)
replyToreply to addresses, separated by a comma (since 5.0.0 version)

Full list of attributes (as of September 2016)

to, returnReceipt, getPlainMessage, subject, getBcc, getTo, hashCode, from, setReturnReceipt, wait, getCc, getAttachments, setTo, id, notify, getFrom, attachments, mimeType, setId, notifyAll, getId, getClass, clone, setMessage, setHtmlMessage, getMessage, equals, plainMessage, setAttachments, bcc, getSubject, class, setFrom, getReturnReceipt, message, getPk, setMimeType, setBcc, setCc, toString, htmlMessage, cc, setPlainMessage, pk, getHtmlMessage, getMimeType, setSubject

Read a list of messages from the email server, with filtering​

Syntax

var emailMessages = utils.getEmails(server, port, username, password, protocol, useTLS, maxMessagesToRead, notReadFilter, startSendDateFilter, endSendDateFilter, startReceiveDateFilter, endReceiveDateFilter, fromAddressFilter, subjectFilter, bodyFilter, withAttachments, attachmentsPath, folderName, moveToFolderOnceRead, setAsSeen, deleteEmailWhenRead, debug);

Details

server - server host
port - server port (e.g. 995)
username - username to use when accessing the email server
password - password to use when accessing the email server
protocol - protocol to use when connecting to the email server (e.g. imap, imaps, pop, pops)
ArgumentDescription
useTLSflag used to enabled the TLS mode
maxMessagesToReadmaximum number of messages to read
notReadFilterflag used to filter only messages not read yet
startSendDateFilter - optional parameterif not null, messages to read will be filtered by sendingdate; only the ones next or equal to this date wil be returned
endSendDateFilter - optional parameterif not null, messages to read will be filtered by sendingdate; only the ones previousor equal to this date wil be returned
startReceiveDateFilter - optional parameterif not null, messages to read will be filtered by receiving date; only the ones next or equal to this date wil be returned
endReceiveDateFilter - optional parameterif not null, messages to read will be filtered by receiving date; only the ones previousor equal to this date wil be returned
fromAddressFilter - optional parameterif not null, messages to read will be filtered by the "from address" specified
subjectFilter - optional parameterif not null, messages to read will be filtered and only the ones containing this value in their object will be returned
bodyFilter - optional parameterif not null, messages to read will be filtered and only the ones containing this value in their body content will be returned
withAttachments - optional parameterif not null, messages to read will be filtered and only the ones having at least one attachment will be returned
attachmentsPathabsolute path where saving attachments
folderNamefolder to read; e.g. INBOX; if not specified, it will be set to INBOX
moveToFolderOnceReadmove to the specified folder each message, once read; can be null
setAsSeenflag used to mark as "SEEN" a message just read
deleteEmailWhenReadflag used to delete the email message once read
debug - flag used to debug the communication with the server
emailMessages : return value - list of messages read from the mail box

Attributes contained in each message of the list:

AttributeDescription
idemail identifier, used to delete an email message later
messageNumberindex within the folder of the specific message
fromfrom email addresses
messageemail body
subjectemail subject
mimeTypee.g. "text/plain" or "text/html"
listlist of absolute paths (strings) where the attachments have been saved
sendDatemessage sending date
receiveDatemessage receiving date

Move a list of email messages to another folder ​

Syntax

var ok = utils.moveMessages(server,port, username, password, protocol, useTLS, messageIds,folderName, moveToFolder, setAsSeen, debug);

Details

server - server host
port - server port
username - username to use when connecting to the email server
password - password to use when connecting to the email server
protocol - protocol to use when connecting to the email server
ArgumentDescription
useTLSflag used to enabled the TLS mode
messageIdslist of email message identifiers, related to emails to move
folderNamesource folder (e.g. INBOX), where the email messages are stored
moveToFolderdestination folder (e.g. Archivio)
setAsSeenflag used to mark the email as seen
debug - flag used to debug the process

Mark a list of email messages as seen or not seen ​

Syntax

var ok = utils.markMessagesAsSeen(server,port, username, password, protocol, useTLS, messageIds,folderName, setAsSeen, debug);

Details

server -server host
port - server port
username - username to use when accessing the email server
password - password to use when accessing the email server
protocol - protocol to use when connecting to the email server
ArgumentDescription
useTLSflag used to enabled the TLS mode
messageIdslist of email message identifiers, related to emails to move
folderNamesource folder (e.g. INBOX), where the email messages arestored
setAsSeenflag used to mark the email as seen or not seen
debug - flag used to debug the process

Delete a list of email messages ​

Delete a list of emails from the specified folder by moving them to the trash folder, starting from a list of messages identified both by a list of email ids and a list of corresponding email indexes.

Both properties can retrieved through the message js object returned by the utils.getEmails method.

Syntax

var ok = utils.deleteMessages(server,port, username, password, protocol, useTLS,messageIdsToDelete, messagesNumbersToDelete,folderName,trashName);

Details

server -server host
port - server port
username - username to use when accessing the email server
password - password to use when accessing the email server
protocol - protocol to use when connecting to the email server
ArgumentDescription
useTLSflag used to enabled the TLS mode
messageIdsToDeletelist of email message identifiers to delete; this value can be fetched from the email message js object
messageNumbersToDeletelist of email message numbersto delete; this value can be fetched from the email message js object
folderName-folder name where themessages to delete are located (e.g. INBOX)
trashName-identifier of the Trash folder; since this name changes according to the specific email provider, it is not necessarely the value "Trash". If you don't know it, you can try with "Trash" and in case of errors, Platform would log the whole list of folders supported by the email provider.

Delete a list of email messages starting from filtering conditions​

Delete a list of email messages from the specified folder by moving them to the trash folder, starting from a filtering condition. At least one filtering condition is required (one of the four date filters)

Syntax

var ok = utils.deleteMessages(server,port, username, password, protocol, useTLS, startSendDateFilter, endSendDateFilter, startReceiveDateFilter, endReceiveDateFilter, messagesNumbersToDelete, folderName, trashName);

Details

server -server host
port - server port
username - username to use when accessing the email server
password - password to use when accessing the email server
protocol - protocol to use when connecting to the email server
ArgumentDescription
useTLSflag used to enabled the TLS mode
startSendDateFilter-optional filterif specified, only messages sent after the specified date will be deleted
endSendDateFilteroptional filter: if specified, only messages sent beforethe specified date will be deleted
startReceiveDateFilteroptional filter: if specified, only messages receviedafter the specified date will be deleted
endReceiveDateFilteroptional filter: if specified, only messages received beforethe specified date will be deleted
trashName-identifier of the Trash folder; since this name changes according to the specific email provider, it is not necessarely the value "Trash". If you don't know it, you can try with "Trash" and in case of errors, Platform would log the whole list of folders supported by the email provider.
folderName-folder name where themessages to delete are located (e.g. INBOX)

Forward an email to the specified destination ​

Syntax

var ok = utils.forwardEmail(server,port, username, password, protocol, useTLS,to, subject subject, text, messageId);

Details

server -server host
port - server port
username - username to use when accessing the email server
password - password to use when accessing the email server
protocol - protocol to use when connecting to the email server
ArgumentDescription
useTLSflag used to enabled the TLS mode
todestination address
subjectadditional title to add to the original one
textadditional text to add to the body of the email
messageIdlist of email message identifiers to delete

Save a list of email messages on the server file system​

Available since 5.2 version. Uses eml format.

Messages to save are identified by a list of message id, so utils.getEmails() method mustbe invoked first, in order to get the identifiers needed here to fetch the messages to save.

Syntax

var ok = utils.saveEml(String server,Integer port, String username, String password, String protocol,Boolean useTLS,String folderName,String[] messageIds,String[] fileNames,Long directoryId);

Details

server -server host
port - server port
username - username to use when accessing the email server
password - password to use when accessing the email server
protocol - protocol to use when connecting to the email server
ArgumentDescription
useTLSflag used to enabled the TLS mode
folderName-folder identifier, where the messages are located; the folder name changes according to the mail server; an example is INBOX
messageIds-a list of message identifiers to save, previously fetched through a getEmails() method invokation
fileNames-file names to use when saving the messages; this list must have the same length of the message ids list, one for each id
directoryId-directory identifier, used to identify the path on the server file system, when all messages will be saved

The method returns the list of messages ids not found in the specified folder and, consequently, not saved.

Send an SMS message through some carrier ​

Important note: an SMS provider must be configured first.
Two alternatives are allowed:

  • Twilio web service; you have to configure two parameters: TWILIO_ACCOUNT_ID and TWILIO_AUTH_TOKEN
  • an email gateway can be used; in that case, you have to configure the SMS_SMTP_xxx parameters and the phone numbers must be expressed appropriately.

Syntax

var json = utils.sendSmsMessage(String fromPhoneNr,String toPhoneNr,String text,Boolean logMessage);

Details

ArgumentDescription
fromPhoneNrphone number used to identify the starting device
toPhoneNrphone number where the message will be sent
texttext message to send
return an outcome, expressed as a JSON string, containing{ "success": true } if the operation has been completed successfully, { "success": false, "message": "..." } otherwise

Pay attention to the phone number format, with should always include the international prefix:e.g. +0039....

Send an email, using SMTP settings passed forward and with a template text​

This method allows to send an email message with optional attachments, starting from a text representing the template for the email body.

No template id is required here: the body text must be provided instead.

This method is helpful when there is not a single template to use, but a variety of alternative templates to use, according to specific conditions, like a different text per language, company id, site id, etc.

Decoupling the template id from the template text, allows to pass forward a different text, not directly connected to a template, which not necessarely must be used here.

Syntax

var ok = utils.sendEmailWithMessageTemplateWithSettings(
String subject,
String messageTemplate,
Map jsObj,
String from,
String to,
String cc,
String bcc,
String priority,
Boolean isHtmlContent,
Boolean returnReceipt,
String smtpHost,
String smtpPort,
String protocol,
String smtpUsername,
String smtpPassword,
String useTLS,
Boolean zipFiles,
Map additionalSettings,
Long dirId,
String... filesToAttach
)

Details

ArgumentDescription
subjectemail subject; can contain variables to replace, expressed as :XXX
messageTemplateemail body; can contain variables to replace, expressed as :XXX
jsObja collection of variable names/values, expressed as a javascript object { varName1: value1, ... } used to replace the subject/body content for all :XXX occurrences
fromemail address sender
toemail address destination; can contain multiple addresses, separated by a comma (,)
ccoptional argument: can be null; carbon copy addresses
bccoptional argument: can be null; blind carbon copy addresses
priorityoptional argument: can be null; define the email message priority
isHtmlContenta boolean flag used to define if the body content is in HTML format or not
returnReceipta boolean flag used to request a return receipt to the destinations
smtpHostSMPT host name to use
smtpPortSMTP port
useTLSflag to use (Y/N) to enable TLS
protocolProtocol to use (e.g. smtp vs smtps)
smtpUsernameSMTP username to use to authentication to the SMTP server
smtpPasswordSMTP password to use to authentication to the SMTP server
zipFilesa boolean flag used to compress all files to attach in a unique zip file and send it, in order to reduce the email size
additionalSettings

can be null; if specified, it represents a javascript object containing additional settings:

{

elmDirId = <number>

elmFileName: "filename.elm"

}

dirIddirectory identifier, where attachment files are located; can be null, in case no attachment files are required
filesToAttacha list of files to attach, separated by a comma; use [] to not include files; each file is expressed as "subdir/filename" , with regards to the base path expressed through the dir id; GCS are supported as well

This method returns false if the email has NOT been sent correctly (e.g. attachment file not found).

Example

Suppose to send an email, whose content changes according to the language and the company id and site id, but there can be templates not always defined for all company+site+language combinations, so that if a template is not found at company+site+language it can be found at company+language and if not found yet, at language only level.

In such a scenario, template messages can be stored on the Platform server file system as text files, organized in a series of subfolder, hierarchically:

invoice_IT.txt
invoice_EN.txt
00000
invoice_IT.txt
invoice_EN.txt
100
invoice_IT.txt
invoice_EN.txt
101
...
00001
...

Email subject must be translated according to the language as well. This can be done either by including subject as the first line of the file or by creating a second text file for subjects only or by including a custom translation in Platform. In this example, we suppose the email subject is defined as a Platform custom translation.

var smtpHost = "smtp.mandrillapp.com";
var smtpPort = "2525";
var protocol = "smtp";
var smtpUsername = "...;
var smtpPassword = "...";
var useTLS = "E";

var dirId = 69; // this entry represent a GCS bucket where attachments are located
var filesToAttach = [ "10I3P.jpg" ];

function getMessageTemplateFile(baseDir) \{
var files = utils.getFilesInPath(baseDir);
for(var i=0;i<files.length;i++) \{
if (files[i]=="invoice_"+userInfo.languageId+".txt") \{
return baseDir+"/"+files[i];
\}
if (files[i]=="invoice_EN.txt") \{ // second choice: use EN as a default
return baseDir+"/"+files[i];
\}
\}
return null;
\}

// let's get template message...
// 1. first check for file in the longest path: company/site
var templateBaseDirId = 49;
var templateBaseDir = utils.getDirectoryPath(templateBaseDirId); // base dir where all template messages are located
var messageTemplateFile = getMessageTemplateFile(templateBaseDir+"/"+userInfo.companyId+"/"+userInfo.siteId);
// 2. second choice: check for file in the path: company
if (messageTemplateFile==null)
messageTemplateFile = getMessageTemplateFile(templateBaseDir+"/"+userInfo.companyId);
// 3. last choice: check for file in thebase path:
if (messageTemplateFile==null)
messageTemplateFile = getMessageTemplateFile(templateBaseDir);

if (messageTemplateFile==null)
throw "No message template found";
else \{
// get tempkate messgae file content...
var messageTemplate = utils.readTextFile(messageTemplateFile,"UTF-8");

// send email...
var ok = utils.sendEmailWithMessageTemplate(
"Ciao", // utils.getResource("invoice.subject"), // subject
messageTemplate,
\{
NAME: "John",
SURNAME: "Smith"
\}, // jsObj
"...", // from
"...", // to
null, // cc
null, // bcc
null, // priority
true, // isHtmlContent
false, // returnReceipt,
smtpHost,
smtpPort,
protocol,
smtpUsername,
smtpPassword,
useTLS,
false, // zipFiles,
dirId,
filesToAttach
);
if (!ok)
throw "Error while sending the email";
\}

Send an email, using the default SMTP settings with a template id​

This method allows to send an email message with optional attachments, starting from a template defined through the UI -> Templates functionality.

This method is helpful for sending a simple email message, having dinamic content and starting from a fixed template and default email settings.

Syntax

var ok = utils.sendEmailWithTemplate(
String subject,
Long templateId,
Map jsObj,
String from,
String to,
String cc,
String bcc,
String priority,
Boolean isHtmlContent,
Boolean returnReceipt,
Boolean zipFiles,
Long dirId,
String... filesToAttach
)

Details

ArgumentDescription
subjectemail subject; can contain variables to replace, expressed as :XXX
templateIdtemplate id defined previously and used to get the email body
jsObja collection of variable names/values, expressed as a javascript object { varName1: value1, ... } used to replace the subject/body content for all :XXX occurrences
fromemail address sender
toemail address destination; can contain multiple addresses, separated by a comma (,)
ccoptional argument: can be null; carbon copy addresses
bccoptional argument: can be null; blind carbon copy addresses
priorityoptional argument: can be null; define the email message priority
isHtmlContenta boolean flag used to define if the body content is in HTML format or not
returnReceipta boolean flag used to request a return receipt to the destinations
zipFilesa boolean flag used to compress all files to attach in a unique zip file and send it, in order to reduce the email size
dirIddirectory identifier, where attachment files are located; can be null, in case no attachment files are required
filesToAttacha list of files to attach, separated by a comma; use [] to not include files; each file is expressed as "subdir/filename" , with regards to the base path expressed through the dir id; GCS are supported as well

This method returns false if the email has NOT been sent correctly (e.g. attachment file not found).