Skip to Content

Overview:

  • Business scenario, where it is required to extract mail attachments and store it to some SAP directory.
  • Here, one common mail-id is been used by a group of users to send mail-attachments from their respective ends.
  • There may be two cases:
    1. One attachment per unread Mail
    2. Multiple attachment per unread Mail

 SAP PI Scenario details:

  • One SAP-PI’s “Mail to File Inbound Asynchronous” interface will be created to achieve above requirement.
  • Using Mail Sender Adapter, interface will read all mail with their attachments.
  • Using File Receiver Adapter, interface will download attachments to the directory.
  • Here only Integration Directory’s configurational objects are required.
  • As no message transformation is in scope, so Integration Repository objects are not required.

Pre-requisites:

  • SAP-PI should have SMTP mail server accessibility
  • SAP-PI should have access to SAP ECC application server’s directory

Steps to develop Interface in SAP-PI:

In SAP-PI’s Integration Directory, we need to follow below steps to develop “Configuration Scenario” of “Mail to File Inbound Asynchronous” interface:

Note: Object naming conventions is for example purpose, it can be as per client’s conventions

[I]. Business Components: Create two business components, one for sender and other for receiver

  1. Sender Business Components
    • This will work on behalf on sender-side while reading Mails
    • Name it as SENDER_BS_COMP
  2. Receiver Business Components
    • This will work on behalf on receiver-side while storing attachments to directory Mails
    • Name it as RECEIVER_BS_COMP

[II]. Communication Channels:

   Channel config for “Case-1: One attachment per unread Mail“:

Here, with help of below config, one attachment can be easily stored to folder.

  1. Sender Mail Adapter Communication Channel

Here, we use ‘Mail Adapter’ to read mails from mail server and configure below details in channel “SENDER_MAIL_CHNL”:

    • We use ‘Transport Protocol’ IMAP4 (Internet Message Access Protocol) to retrieve e-mails from a folder of an e-mail server.
    • It reads mail from INBOX folder and post read, mark its status to ‘read’.
    • Using ‘Message Protocol’ XIPAYLOAD, The content of the e-mail is put in the payload of the XI/PI message.
    • Enable ‘Keep Attachments’ functionality while reading mails.
    • Enable ‘Set Adapter-Specific Message Attributes’ functionality while reading mails, this is required to get header details of message. From header details we extract attachment names.
    • As we need to extract all attachments of one mail, this can be achieved with help of below Module Beans:
      1. Module Bean ‘PayloadSwapBean
        • With help of this bean, we swap mai payload with 1st attachment
        • And with help of File-Receiver channel we will download it to folder
      2. Module Bean ‘MultipartHeaderBean
        • With help of this bean, we adds the following values in dynamic configuration:
        • Attributes of other payloads that are appended to the XI message as an additional attachment
      3. Module Bean ‘DynamicConfigurationBean
        • We use this bean in File-Receiver channel.
        • This will help to download rest attachment (other than 1st attachment)
  1. Receiver File Adapter Communication Channel

Here, we use ‘File Adapter’ to download attachment to folder and configure below details in channel “RECEIVER_FILE_CHNL”:

    • 1st attachment is already ready to get downloaded, which is swapped with main-payload
    • Using ‘DynamicConfigurationBean’, get 1st attachment’s original name
    • Please note: Here, with this config we can not store multiple attachments from one mail to folder
    • Here ‘File Name Scheme’ is referring to variable which is defined in ‘Variable Substitution’
    • Define a variable ‘fname’ using Variable Substitution, which stores message interface name.
    • Use Module Bean ‘DynamicConfigurationBean’, to get 1st attachment’s original name using logic “Mail  Part[1].Content-Description” and set it to message interface name

 

   Channel config for “Case-2: Multiple attachment per unread Mail“: 

Here, we use custom adapter module at File-Receiver-Channel side.

  1. Sender Mail Adapter Communication Channel Config
  2. Receiver File Adapter Communication Channel Config
    • Here, using File Receiver, one Temp file will be generated in directory, we keep it over-writing every time.
    • Now one custom adapter module will be used, which will have below functionalities:
      • Read all incoming attachments from inbound message
      • Store it to folder path with original attachment names
    • Code and steps to create above custom adapter module will be updated soon in my next blog……..
    • Below Module configurations required in File-Receiver-Channel for custom adapter module access, that require input as FolderPath

 

[III]. Receiver Determination

  • receiver determinationis required to specify the receiver or receivers of the message, as well as conditions for the forwarding of the message to the receiver or receivers
  • Here we create it with below parameters:
Sender
Communication Component SENDER_BS_COMP
Interface INT_MailToFile
Namespace NM_MailToFile
Receiver
Communication Component  *
Configured Receiver RECEIVER_BS_COMP

 

[IV]. Interface Determination

  • An interface determination is required to specify the inbound interface of a specified receiver that a message is to be sent to. We can also define mappings here, if required.
  • Here we create it with below parameters:
Sender
Communication Component SENDER_BS_COMP
Interface INT_MailToFile
Namespace NM_MailToFile
Receiver
Communication Component RECEIVER_BS_COMP
Receiver Interfaces
Name INT_MailToFile
Namespace NM_MailToFile

 

[V]. Sender Agreement

Sender
Communication Component SENDER_BS_COMP
Interface INT_MailToFile
Namespace NM_MailToFile
Receiver
Communication Component
Sender Communication Channel SENDER_MAIL_CHNL

[VI]. Receiver Agreement

Sender
Communication Component SENDER_BS_COMP
Interface INT_MailToFile
Namespace NM_MailToFile
Receiver
Communication Component
Receiver Communication Channel RECEIVER_FILE_CHNL

 

To report this post you need to login first.

13 Comments

You must be Logged on to comment or reply to a post.

  1. Evgeniy Kolmakov

    Hi Dilip!

    Wouldn’t you please provide more detailed explanation of how multiple attachements within one message are processed. I guess it’s not clear enough. For now I could see the logic to send the first attachment only. Or did I miss anything?

    Regards, Evgeniy.

    (1) 
    1. Dilip Kumar KrishnaDev Pandey Post author

      Dear Evgeniy Kolmakov

      With help of above Interface,

      • Mails having multiple attachments can be read
      • and all attachments (like pdf, excel, file) of a mail from Mail-Inbox can be downloaded to folders
      • Post read, each mail will have status ‘UnRead’

      About, how multiple attachments get downloaded to folders, below are the details:

      At Sender side:

      • Module parameter “PayloadSwapBean“, swaps 1st attachments with main-payload.
      • “MultipartHeaderBean” adds the following values in dynamic configuration:
        • Attributes of other payloads that are appended to the XI message as an additional attachment.

      At Receiver Side:

      •  With help of “DynamicConfigurationBean” and “Variable Substitution” interface is able to download multiple attachments in to the directory

       

      I hope, above clarifies things.

       

      Thanks & Regards,

      Dilip.

      (0) 
      1. Evgeniy Kolmakov

        Hi Dilip!

        I feel a little bit confused. Does the file adapter at receiver’s side handle attachments? How are attachments saved?

        And if I understand the logic right, mail body is going to be saved too?

        Regards, Evgeniy.

        (0) 
        1. Dilip Kumar KrishnaDev Pandey Post author

          Dear Evgeniy Kolmakov

          Receiver File adapter will downloads attachments to folder directory.

          Mail body is not going to be saved, because we are replacing mail body with 1st attachment,

          and rest attachments will be handled using “DynamicConfig’ of channel.

          I have updated the blog for more clarifications, hope that will be enough for understanding the scenario working.

          Thanks & Regards,

          Dilip.

          (0) 
  2. Evgeniy Kolmakov

    Hi Dilip!

    1. Receiver file adapter doesn’t support working with attachments.
    2. When you use PayloadSwapBean, payloads are swapped – attachment is moved to main payload and the main payload, if any, moved to attachment (as module name even says).
    3. DynamicConfiguration attributes and Variable Substitution are intended to be used with main payload, not with attachments.

    So let me ask: have you ever tried to implement the scenario you describe in your blog?

    Regards, Evgeniy.

     

    (0) 
    1. Dilip Kumar KrishnaDev Pandey Post author

      Dear Evgeniy Kolmakov

      This is a working scenario, can download multiple attachments of a mail to directory.

      • Mail Adapter Module parameters
      • File Adapter Module Parameters
      • And SXMB_Moni log screen

      As per above log screen, when Mail adapter reads a mail, it forwards all its attribute to receiver side.

      Now using ‘DynamicConfig‘ and ‘variable substitution’ parameters, interface can download attachments to folders.

       

      Thanks & Regards,

      Dilip.

      (0) 
        1. Dilip Kumar KrishnaDev Pandey Post author

          Dear Evgeniy Kolmakov

          At receiver side, in mapped folder, we get all attachments with their original naming conventions and file extensions (pdf, excel, txt…etc.)

          And thank you for your time and detailed observations, that made me understand, how one blog should be more informative for clear picture of the Idea.

           

          Thanks & Regards,

          Dilip.

          (0) 
        2. Manoj K

          Agree with Eve , reading multiple attachment from sender mail was never an issue . But the main concern was to drop all the attachments via one single message. Additional in your File channel you are reading Attachment name from Part[1]Content-Description  which will always have the first attachment name only and channel will always drop only the first attachment as you have swapped with first attachment only  .Also i believe you have variable substitution also as you needs to assign the message.interface for filename attribute of file channel.

          I am really not a blogger but my suggestion is to always put a screenshot of your config as picture talks more than 1000 words.

          Br,

          Manoj

          (1) 
              1. Dilip Kumar KrishnaDev Pandey Post author

                Dear Eve/Manoj,

                You both are right, about below things:

                • File Receiver adapter can’t handle multiple attachments
                • Part[1]Content-Description  which will always have the first attachment name only and channel will always drop only the first attachment as you have swapped with first attachment only

                About above blog:

                • It reads mail with multiple attachments, forwards all attachments with main-payload to receiver side, and stores only 1st attachment in to the directory using configured parameters in Receiver-File-Adapter-channel.
                • Multiple attachment is been downloaded with help of Receiver-SFTP-Adapter-Channel using same Module config, but few corrections still required, I am working on it.

                 

                I will re-update blog with new details shortly.

                Thanks & Regards,

                Dilip.

                (0) 
                1. Manoj K

                  Yes Dilip you are right with SFTP you can handle it as there is option of “Store Attachment” along with additional Parameter retain.attachment name . But in this case you need to drop only all the attachments so you need to find a way to suppress the main payload.

                   

                  (0) 

Leave a Reply