Create a Zip File and Send It as an Email Attachment in Mule 4
In this article, see a tutorial on how to create a zip file and send it as an email attachment in Mule 4.
Join the DZone community and get the full member experience.Join For Free
We will be using the Compression Module of Mule 4 for creating a zip file and email component to send as attachment
- Compression Module (Install the compression Module from Mulesoft)
- Gmail Account (Third-party Application enabled)
Step 1: Creating a sample flow to list all the files in the directory
Step 2: Add the Compression Module Archive component. This component creates the zip of all the files read by the LIST component.
We will be adding the
transform message to create a map of the key-value pair of Filename and the Payload of the file.
Step 3: Add the send component of the email
Step 4: We need to use the below config for the send component:
Note: If we don't add the empty quotes "" in the content tab, an additional file will be sent to overcome that, so we use "". And also, we need to specify the key name as "fileName.zip" so that once we download the file, we should able to open a zip file.
Step 5: Run the project. We will be getting an email with an attachment as a zip file .
Step 6: Download the file and open it using the WINRAR extractor
Opinions expressed by DZone contributors are their own.