IBM Support

How to change the file name in an e-mail attachment

Technical Blog Post


How to change the file name in an e-mail attachment


Changing the attachment name in a business process is not difficult, but until you know the tricks, it can be maddening. After a little experimentation, I created a sample business process that seems to do the job.  I will spare you the wailing and gnashing of teeth that accompanied my first efforts, sharing only what I found to work.

As you will see, there are a few things that will make the journey more pleasant.

1. If your file name will be created from concatenated values, it is probably best to get this out of the way.  (Should you need to pass values via message_to_child, it's simpler to pass only one.)
2. Use the Get Document Info Service and update both BodyName and DocumentName. Set updateMetaDataOnly=true; as per our documentation (, "If set to true, the service can set the following metadata without creating a new document that is stored in the database:

  • doc name
  • bodyName
  • char_encoding
  • subject
  • content_type
  • content_subtype
  • doc size"

And now, the process ...

<process name="fixAttachment">
   <!-- in my original test, these values were already in
        the ProcessData -  this simulates the same.
   <assign to="/CODE_LIST/PRODUCER">ourProducer</assign>
   <assign to="/CODE_LIST/MESSAGE_TYPE">ourMessage</assign>
   <assign to="/WORKFLOW_ID">12345</assign>
   <assign to="/TIME_STAMP">20180901</assign>
   <assign to="/CODE_LIST/FILE_TYPE">.txt</assign>
    <!-- rather than passing the concat statement to the
         Get Document Information Service, it seems
         more concise to handle this ahead of time by
         creating newFileName

   <assign to="newFileName" from="concat (/ProcessData/CODE_LIST/PRODUCER/text(), '_',
   /ProcessData/CODE_LIST/MESSAGE_TYPE/text(), '_',
   /ProcessData/WORKFLOW_ID/text(), '_',
   <operation name="Get Document Information Service">
   <participant name="GetDocumentInfoService"/>
    <output message="GetDocInfoServiceInputMessage">
      <!-- DocumentName is the key to making this work.
           I hedged my bets and set BodyName just for
           good measure!

      <assign to="BodyName" from="/ProcessData/newFileName/text()"/>
      <assign to="DocumentName" from="/ProcessData/newFileName/text()"/>
       <assign to="updateMetaDataOnly">true</assign>
       <assign to="." from="*"/>
     <input message="inmsg">
       <assign to="." from="*"/>
   <operation name="Mail Mime Service">
     <participant name="MailMimeService"/>
     <output message="MailMimeServiceInputMessage">
       <assign to="mail-mime-operation">build</assign>
       <assign to="mail-mime-recipient"></assign>
       <assign to="mail-mime-subject" from="concat('Here is the file, ', /ProcessData/newFileName/text(), ', you zany guy!')"/>
       <assign to="mail-mime-sender"></assign>
       <assign to="mail-mime-body">true</assign>
       <assign to="mail-mime-set-attachment">true</assign>
      <assign to="mail-mime-use-doc-area">true</assign>
       <assign to="." from="*"/>
     <input message="inmsg">
       <assign to="." from="*"/>
   <!-- Send Email -->
   <operation name="SMTP Send Adapter">
     <participant name="SMTP_SEND_ADAPTER"/>
     <output message="SMTP_SEND_ADAPTERInputMessage">
       <assign to="b2b-raw-message">true</assign>
       <assign to="xport-smtp-mailhost"></assign>
       <assign to="xport-smtp-mailport">25</assign>
       <assign to="." from="*"/>
     <input message="inmsg">
       <assign to="." from="*"/>

   <!-- Get Document Info Service is quite useful, but it adds a lot
          to the ProcessData. I prefer to clear out extraneous values.

   <operation name="Release Service">
   <participant name="ReleaseService"/>
   <output message="ReleaseServiceTypeInputMessage">
     <assign to="TARGET">/ProcessData/*[ starts-with(name(), 'Document') ]</assign>
     <assign to="." from="*"/>
   <input message="inmsg">
     <assign to="." from="*"/>

Now for the moment of truth!  Would it work?  I submitted a file named estragon_850.edi to the BP and received an e-mail in response:

Here is the file, ourProducer_ourMessage_12345_20180901.txt, you zany guy!
Tue, Aug 28 1:27 PM
From: siadmin <> To: me

ourProducer_ourMessage_12345_20180901.txt 1.0 K

Mission accomplished.  I then feasted on toast and tea in celebration.

[{"Business Unit":{"code":"BU012","label":"WCE"}, "Product":{"code":"SSMHNK","label":"IBM Sterling B2B Integrator"},"Component":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"","Edition":""}]