IBM Support

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

Technical Blog Post


Abstract

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

Body

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 (https://www.ibm.com/support/knowledgecenter/en/SS3JSW_5.2.0/com.ibm.help.svcs_adpts_a_l.doc/Get_Doc_Info_svc.html), "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">
 <sequence>
   <!-- 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(), '_',
   /ProcessData/TIME_STAMP/text(),
   /ProcessData/CODE_LIST/FILE_TYPE/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="*"/>
     </output>
     <input message="inmsg">
       <assign to="." from="*"/>
     </input>
   </operation>
 
   <operation name="Mail Mime Service">
     <participant name="MailMimeService"/>
     <output message="MailMimeServiceInputMessage">
       <assign to="mail-mime-operation">build</assign>
       <assign to="mail-mime-recipient">junior_philpots@us.ibm.com</assign>
       <assign to="mail-mime-subject" from="concat('Here is the file, ', /ProcessData/newFileName/text(), ', you zany guy!')"/>
       <assign to="mail-mime-sender">siadmin@ibm.com</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="*"/>
     </output>
     <input message="inmsg">
       <assign to="." from="*"/>
     </input>
   </operation>
   <!-- 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">odysseus.ibm.com</assign>
       <assign to="xport-smtp-mailport">25</assign>
       <assign to="." from="*"/>
     </output>
     <input message="inmsg">
       <assign to="." from="*"/>
     </input>
   </operation>

   <!-- 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="*"/>
   </output>
   <input message="inmsg">
     <assign to="." from="*"/>
   </input>
   </operation>
 </sequence>
</process>

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 <siadmin@foo.com> 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":""}]

UID

ibm11120569