Sample email flows: attachments
Note: Sample flows are provided by OL Connect Automate, once installed. It appears in the flows folder in the Import dialog in Node-RED which allows you to import the sample into a new or existing flow; see Importing and Exporting Flows in the Node-RED documentation. Instructions are given in this topic, but can also be found in the Read me comment that comes with the sample flow.
For a list of all sample flows, see Sample flows.
These sample email flows generate email messages including a static PDF and a PDF generated based on the print context of the template. The flows are either triggered using an inject node that provides a hard-coded path to a data file in msg.filename
or by using an http in node that listens to POST requests.
Prerequisites
Before running either sample flow:
-
Download the following resources and deploy them to the OL Connect Server using the Send to Server option in OL Connect Designer (see Sending files to Connect Server or to another server):
-
Create the following directory in the root of your drive before deploying this example:
\workspace\email\invoices
-
Download the following resources and save them in the
\workspace\email\invoices
directory. -
In the settings of the data mapping, email content and sendgrid node, select the OL Connect Server to which the resources are sent.
-
Sign up with sendgrid.com for a trial or full account.
-
Create an API Key via the Settings section of the SendGrid dashboard.
-
In the settings of the sendgrid node of the flow:
-
Enter the key in the API Key field.
-
Select the Send all messages to the Test address option.
-
Enter your email address in the Test address field.
-
Add the Print context as attachment
This flow generates personalized email messages for XML data using the email content node and sends the result via the SendGrid service.
The data mapping node extracts data from a data file and stores the data in the OL Connect database.
The email content node merges this data with a template, returning an array with information about the generated messages in msg.payload
.
This data is processed by the sendgrid node which sends the email messages using the SendGrid API.
Use the inject nodes to trigger the process with a data set of 2 records or 10 records.
Trigger based on submitted JSON data (POST request)
For this example the http in node is set up to listen to POST requests.
Use the tool Postman.app to submit sample data this process.
-
Add a request using the POST method. Sample URL:
http://localhost:1880/email/invoices
-
Click Body and choose raw.
-
Add the JSON data below to the text area and before posting, set the format of the
raw
data to JSON.
[
{"id": "1",
"first": "Pauline", "
"last": "Kennermann",
"email": "pkennermann0@olacme.com",
"guid": "047c5549-14fb-432f-817f-d38e898bfdf7",
"invoice": "INV1634096",
"details": [
{"number": "375428",
"description": "Hot Hands Hand Warmers 10 Pack",
"unitprice": "19.99",
"quantity": "2",
"total": "39.98"
},
{"number": "248553",
"description": "Therm-ic BasicKids Set Classic Boot Heaters 2016",
"unitprice": "79.99",
"quantity": "3",
"total": "239.97"
},
{"number": "404644",
"description": "Dakine Pipe 165 Snowboard Bag 2016",
"unitprice": "39.99",
"quantity": "3",
"total": "119.97"
},
{"number": "363869",
"description": "Swix T77 Waxing Iron Economy Waxing Iron 2016",
"unitprice": "59.99",
"quantity": "1",
"total": "59.99"
}
],
"subtotal": "459.91",
"tax": "68.99",
"total": "528.9"
},
{"id": "2",
"first": "Ellene",
"last": "Ciepluch",
"email": "eciepluch1@olacme.com",
"guid": "9b57000a-d57a-4088-89a5-7b37e1b11c28",
"invoice": "INV1092974",
"details": [
{"number": "178399",
"description": "Swix Base Cleaner Liquid - 500ml 2016",
"unitprice": "34.99",
"quantity": "1",
"total": "34.99"
},
{"number": "388459",
"description": "K2 Missy Kids Skis with Marker Fastrack2 7.0 Bindings",
"unitprice": "278.95",
"quantity": "1",
"total": "278.95"
},
{"number": "389374",
"description": "Flow Five Snowboard Bindings",
"unitprice": "129.94",
"quantity": "2",
"total": "259.88"
},
{"number": "248553",
"description": "Therm-ic BasicKids Set Classic Boot Heaters 2016",
"unitprice": "79.99",
"quantity": "2",
"total": "159.98"
}
],
"subtotal": "733.8",
"tax": "110.07",
"total": "843.87"
}
]