Sending Emails

Note: If you are using a private install of WorkflowFirst, then before you can send any emails, you must create the Configuration record, and put in a valid SMTP server and From email address. This isn't necessary in the cloud (hosted) version.

There are several features that allow for emails to be sent from your WorkflowFirst application. Workflow will send out emails to the originator of the workflow, and will also set up notifications. The benefit of notifications is that users can choose to subscribe to them. There are other features like document review and data entry reminders that will also send out emails. Information on these can be found in the Enterprise Features section.

You can also send emails from script. To do this, use the EMailUser function. You simply pass in the user, subject, body and an optional attachment. The user can either be a user record (loaded from the /Users list), or an email address. If you don't want to send an attachment, put in Nothing():

call EMailUser("[email protected]", "This is a test subject", "Hello, this is a test message", Nothing())

Or, instead of an email address, if you want to send the email to the originator of a workflow item you can replace that with load(&root/Users[UserID=#rec/Originator]) (if you were running this from a workflow stage script).

The attachment is a file object. There are several ways you can get a file to send.

The first is to retrieve a file in the database. You can specify a "File" data type, and this provides an easy way for users to select and upload a file. To load the file from the database, you need to explicitly ask for it - it won't be loaded otherwise, for performance reasons.

var #rec = load(&path with files)

Notice the "with files". This instructs the load statement to retrieve the files in the record. So let's say you had a file in a field called Image. That statement above will put the file object into the field called Image. That's a file object you can send as an attachment:

call EMailUser("[email protected]", "The product you ordered", "We've attached an image of the product.", #rec/Image )

Another way to get a file object is to run a report. If you've defined a report, you can use the RunReport function to run that report internally and return a file object containing the PDF of the file.

var #file = RunReport(&path, "MyReport")
call EMailUser("[email protected]", "The report you requested", "Here is the report you requested.", #file )

You can also email multiple addresses with potentially multiple attachments. To do this you need to create a list of email addresses and a list of attachments. You can create these kind of arbitrary lists using the NewLlist() function, and then "add" to add things to them. Here's an example:

var #emails = NewList()
add "[email protected]" to #emails
add "[email protected]" to #emails
var #attachments = NewList()
add RunReport(&path, "MyFirstReport") to #attachments
add RunReport(&path, "MySecondReport") to #attachments
call EMailUsersEx(#emails, "Your reports", "Here are your reports", #attachments)


Please post all questions on the support forum. Thank you.