Write to File

In previous post email-responder-write-to-database, we have stored email information in database successfully. As for last part of first use case, our aim is to create one folder with “from address” and storing attachments in that and storing the body of the email in a text file.

1. Drag a choice component into scatter-gather and add loggers as place holders
Configure the choice component as shown below.

The MEL (Mule Expression Language), payload.name will have the name of the attachment if the email has attachment else it will be null.

2. When the email has no attachments the choice routes to Default flow. Drag a file component into the default flow and configure it as shown below.

Basic Settings

3. Processing mail attachments to file system

Create a new variable called attachmentName and set it with #[payload.name] (This would be the name of the attachment file in the email)

Drag a file component into the flow after attachmentName and configure it as shown below.


  • Right click on the project. Select Run As –> Mule Application
  • You will see logs running in the console and finally the application will be deployed.
  • Send an email and check your console. You will see that your flow is being kicked off mail
  • Now, see the console it is showing the just got email information…
  • Check your file system. We would expect that a folder (senders email address) will be created inside F:\mule_cases
  • Inside which we would have a text file (subject name) having the body of the email and a folder having all the attachments in the email.

Complete code can be seen below or downloaded from