sendEmail Documentation
Purpose
The sendEmail logic is designed to facilitate the sending of emails containing the output data of a workflow. Utilizing Intuidy's internal email service (noreply@intuidy.com), it allows users to configure email recipients, subject lines, and email body templates. This logic streamlines communication by ensuring relevant workflow results are promptly shared with specified recipients.
Settings
The sendEmail function has various settings that dictate the behavior and appearance of the emails sent. Below is a detailed explanation of each setting.
1. Recipient Configuration (to)
- Input Type: String
- Description: This setting defines the email addresses of the recipients. Multiple email addresses can be separated by commas. The function parses and trims this string to create an array of individual email addresses.
- Impact of Changing: Altering this setting changes who receives the email. If improperly configured or invalid emails are provided, the function will throw an error and fail to send the email.
- Default Value: No default value; the absence of this setting will cause an error.
2. Email Subject (subject)
- Input Type: String
- Description: This setting specifies the subject line of the email. If not provided, a default subject of "Workflow Output" is used.
- Impact of Changing: Modifying this setting will change what recipients see in their inbox as the email subject, which can impact the open rates and organization of emails.
- Default Value: "Workflow Output"
3. Body Template (bodyTemplate)
- Input Type: String (HTML or plain text)
- Description: This optional setting allows users to specify a custom HTML or plain text template for the email body. If provided, this template will be used in place of automatically formatted data.
- Impact of Changing: Different body templates will lead to varied appearances and content in the email body. It provides flexibility for user-defined formats and designs.
- Default Value: No default value; if omitted, the function will apply smart auto-formatting to the input data.
4. Body Format (bodyFormat)
- Input Type: Dropdown (options: 'html', 'text')
- Description: This setting indicates the format of the email body. It determines whether the content should be sent as HTML or plain text. Factors like readability and design can be influenced by this setting.
- Impact of Changing: Selecting 'html' allows more visually appealing emails while selecting 'text' would render the content in plain format.
- Default Value: No default value; defaults to HTML if no bodyTemplate is provided.
How It Works
- Input Processing: The function first retrieves the input data (
inputs.input1) to be included in the email body. - Recipient Validation: It processes the recipient email(s) from the configuration, trims whitespace, and checks for valid email formats. If the recipient(s) aren’t valid or exceed the maximum count of 50, an error is thrown.
- Email Body Generation: Depending on available configurations, the body is either taken from a custom template (if provided) or generated using smart auto-formatting.
- Email Sending: Finally, it calls the internal
sendWorkflowEmailservice to dispatch the email to the specified recipients, utilizing the configured subject and body. - Output Handling: The function returns a success report containing the email details.
Data Expectations
The sendEmail logic expects the following data structure for inputs:
- inputs.input1: This is the data payload that users wish to send via email. It can include a variety of data types, such as JSON objects, strings, or structured data depending on the workflow output.
Use Cases & Examples
Use Cases
-
Automated Reporting: A marketing department may set up a workflow that generates weekly sales reports. By using
sendEmail, the team can automatically email these reports to key stakeholders every Friday. -
Notification System: An IT operations team can implement
sendEmailas part of a workflow that triggers alerts when system thresholds are breached, ensuring prompt responses to critical issues. -
Client Updates: In a client-services context, firms can utilize
sendEmailto communicate project updates or important information directly to clients as part of their workflow processes.
Detailed Example
Use Case: Automated Weekly Sales Reporting
Scenario: An e-commerce firm wants to send a weekly sales summary every Friday to the sales team.
Configuration Data:
{
"inputs": {
"input1": {
"salesData": [
{"date": "2023-10-02", "revenue": 5000},
{"date": "2023-10-03", "revenue": 7000}
]
}
},
"config": {
"to": "sales_team@example.com, manager@example.com",
"subject": "Weekly Sales Report",
"bodyTemplate": "<h1>Weekly Sales Summary</h1><p><strong>Details:</strong></p><pre>{{salesData}}</pre>",
"bodyFormat": "html"
}
}In this example, the email will be sent to two recipients, containing the title "Weekly Sales Report" and a formatted summary of the sales data in HTML format. Each weekly report can adapt its content based on the dynamically generated input1 data from the workflow.