Attach Excel file to email
This article shows a step-by-step configuration of exporting a data page list to an Excel file and then sending the Excel file as an email attachment. This demo was developed using Pega Platform 8.8.2.
Here is a high-level view of the activity. See the details of each step below.
Step 1 – Set an output Excel file name.
- Notice the file extension (.xlsx) used.
Step 2 – Generate an Excel file by using an OOTB pxGenerateExcelFile activity.
- Do NOT select the DownloadFile checkbox.
- Refer to this article to learn more about how to export a data page list to an Excel file.
Step 3 – Set an output Excel file location.
- System automatically saves the output Excel file to pxProcess.pxServiceExportPath.
Step 4 – Generate an output Excel file stream byte. This Java step converts the Excel output file to a byte stream.
- A local variable (strFileData, String) must be defined in the Parameters tab of the activity.
- A local variable (attach, Boolean) must be defined in the Parameters tab of the activity.
- Open the attached file (Step4_Java_Source_Code.txt) to copy the source code, and paste to your Java step.
Step 5 – Set the attachment properties.
- Under ‘Pages & Classes’ of activity, define a page name (Attachment) with Class (Embed-EmailAttachment).
- Note that .pyData property is set with local.strFileData which contains the Excel file stream byte generated by the previous Java step.
Step 6 – Add the Attachment page to AttachmentList page.
- Under ‘Pages & Classes’ of activity, define a page name (AttachmentList) with Class (Data-EmailAttachments).
- CopyInto = AttachmentList.pyAttachments(1)
- To add another attachment, copy it to AttachmentList.pyAttachments(2) and so on..
Step 7 – Open an Email Account instance, which will be used to send an email with attachment.
- Under ‘Pages & Classes’ of activity, define a page name (Email) with Class (Data-EmailAccount).
For this demo, a Gmail account was used as Sender.
Step 8 – Set the email parameters.
Step 9 – Call an OOTB SendEmailNotification activity to send out an email with attachment.
Step 10 – Clean up temporary pages.
Click “Run” to test the activity. It should send an email with an Excel attachment.