FME Version
Files
-
- 29 Bytes
- Download
Introduction
When running a workspace on FME Flow, it’s possible to send the results of the job via email. When the Data Download service is used, a link to the zip file is included allowing the recipient to download and access the data directly.
This functionality isn’t available by default in workspace apps, but it can be implemented by adding a published parameter and using the Emailer transformer within Workbench.
Requirements
- A compatible version of FME Form and FME Flow.
- Access to an email account compatible with the Emailer transformer.
- Access to a second email account to receive emails for testing. A temporary email service could be used, but if doing so, assume all the information in the email is public, including the “sent from” address.
Step-by-Step Instructions
1. Check Data Download is Working as Expected
Download the JSON file and starting workspace found in the attachments section, and place them in the same directory. Open the workspace in FME Workbench and publish it to FME Flow, ensuring Upload data files is enabled and the Data Download service is selected. See Publishing to FME Flow for more details.
Run the workspace on FME Flow using the Data Download service. There should be no errors, and a Data Download URL should be shown. Clicking the URL downloads the zip file created by the workspace.
2. Access the Data Download Zip File Name
Return to the workspace in FME Workbench.
The FME Flow User Parameter FME_SERVER_DEST_DIR contains the local path to the zip file where output data is written. This path leads to the same zip file, which is accessed by the Data Download service, so extracting its filename will allow the download URL to be reconstructed.
To extract this filename, add a StringSearcher transformer to the workspace and connect the FeatureWriter Summary port to the StringSearcher Input port.
In the Search In parameter, use the drop-down arrow to select FME_SERVER_DEST_DIR by clicking User Parameters > FME Flow Parameters > FME_SERVER_DEST_DIR.
In the Contains Regular Expression parameter, enter:
[^\\]+\.zip$
This is a regular expression matching zip file names in a file path and can be generated using Workbench's AI Assist tool.
Finally, set the value of Matched Result to zipfile_name.
3. Create the Data Download URL
Now that we have access to the zip file's filename, we can create a URL in the same format as the Data Download URL generated in step 1.
Add an AttributeCreator to the workspace. Connect the StringSearcher Matched port to the AttributeCreator Input port.
Create a new Output Attribute named datadownload_url with a Value of:
$(FME_SERVER_WEB_URL)/fmedatadownload/results/@Value(zipfile_name)
4. Create an Email User Parameter
In the Navigator, right-click on User Parameters and click Manage User Parameters. Use the green plus symbol to add a new Text user parameter. Set the following:
- Parameter Identifier: results_email
- Prompt: Email for results to be sent to
- Published: Enabled
- Required: Disabled
- Disable Attribute Assignment: Disabled
- Default Value: <leave blank>
5. Add and Configure an Emailer Transformer
Add an Emailer transformer to the workspace and connect it to the AttributeCreator. In this tutorial, we’ll use a Gmail account with two-factor authentication disabled for simplicity, but using a Gmail web connection is considered best practice. Getting Started with Sending and Receiving Email in FME Form and FME Flow gives details on this.
Configure the Emailer as follows:
Service
- Email Service: Generic SMTP
Connection
- Host: smtp.gmail.com
- Port: 587
- Encryption: TLS
- Timeout (seconds): 60
- Sender Authentication: Enabled, with your username and password.
In the Addressing section of the parameters, set From to your email, and To to the results_email user parameter.
In the Message section, set Subject to something like:
Workspace App Results!
The Body should include @Value(datadownload_url), so the recipient receives the results of the transformation. For example:
Access the results of the workspace app here: @value(datadownload_url)
6. Republish to FME Flow
Your workspace should look like this:
Save the workspace, then republish to FME Flow.
7. Create a Workspace App
In FME Flow, on the side menu, expand Flow Apps, then click Create Workspace App. For this example, we’ve created an app with the following parameters, but they can be customized:
- Title: Example - Emailing a Data Download Link From Workspace App
- Description: <leave blank>
- Repository: <same as Repository selected in step 1>
- Workspace: <same as Workspace selected in step 1>
- Service: Data Download
- Expiration: <leave as default>
- Require Authentication: Disabled
For more detailed instructions on how to create a workspace app, see Getting Started with FME Flow Workspace Apps. Once the workspace app has been created, click on the app URL to open it. Enter your alternative email in the Email for results to be sent to: parameter, run the app, and check your inbox for the data download link.
Adding Email Format Validation
Although the above steps technically provide a solution, this workspace app has no input validation meaning providing a poorly-formatted email or no email at all will cause it to fail. Verify this by running the workspace app without providing an email.
1. Add a Tester
Back in FME Workbench, continuing in the previously built workspace, add a Tester transformer between the FeatureWriter Summary output port and connect the Passed output port to the StringSearcher. In the Tester parameters, add the following test clauses:
Logic | Left Value | Operator | Right Value |
---|---|---|---|
[blank] | $(results_email) | Contains Regex | ^[^@\s]+@[^@\s]+\.[^@\s]+ |
AND NOT | $(results_email) | Contains | [one space*] |
*The second clause’s Right Value should be a single space.
The first clause ensures the email user parameter is an email. Various regex expressions can be used to match emails, but we’ve opted to use one found in this Microsoft article. The second clause ensures there are no spaces in the parameter value.
2. Add a Logger
Although not strictly necessary, logging is important so the user knows why an email may not have been sent. Add a Logger transformer to the workspace and connect it to the Tester Failed output port. Set the Severity Level to Warning and the Log Message to:
Invalid or empty email provided: $(results_email)
All other parameters can be left as default.
3. Republish to FME Flow
Republish the workspace to FME Flow.
Open the workspace app, enter an email to receive the data download link, and ensure the email is received as expected. If something goes wrong, double-check the regex entered in the Tester.
Now, try entering a poorly-formatted email such as "www.notanemail.com", or leave the field blank. The job should complete successfully, but the following line should appear in the job log as a warning.
Comments
0 comments
Please sign in to leave a comment.