Hi Prashanth
Your logic does not do any renaming of the attachment. It just retrieves the attachment name from dynamic configuration (which was stored by mapping) and does nothing to it, it is just kept in the variable targetFileName.
In order to set the filename of the attachment, you need to set it in the Content Type of the attachment. The content type needs to be set in the following format, assuming you are only dealing with plain text MIME types.
text/plain;charset="UTF-8";name="file.txt"
To do this, you need to use setContentType() method of the Payload interface. For your case, you can do something like below:-
payload.setContentType("text/plain;charset=\"UTF-8\";name=\"" + targetFileName + "\"");Make sure this is after the variable has been populated.
Rgds
Eng Swee