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:
- One attachment per unread Mail
- 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
- Sender Business Components
- This will work on behalf on sender-side while reading Mails
- Name it as SENDER_BS_COMP
- 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:
Case-1: One attachment per unread Mail : (Sender/Receiver Comm. Channel Cofig.)
Here, with help of below config, one attachment can be easily extracted from unread mail to sap' app directory.
Sender Mail Adapter Communication Channel:
Select ‘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:
- Module Bean ‘PayloadSwapBean’
- With help of this bean, we swap main payload with 1st attachment
- And with help of File-Receiver channel we will download it to sap app directory
- Module Bean ‘MultipartHeaderBean’
- With help of this bean, we add the following values in dynamic configuration:
- “Attributes of other payloads that are appended to the XI message as an additional attachment”
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
- Test Screens:
- Unread mail in Mail-Inbox with one attachment
- Mail-Content
- Post Mail read by PI-Channel (Mail-Sender-Adapter), below is the channel log
- Sxmb_Moni log:
- And post attachment extraction by interface, file present in sap app directory
Case-2: Multiple attachment per unread Mail : (Sender/Receiver Channel Cofig.)
Here, we use a custom java adapter module at File-Receiver-Channel side.
- For this case, we create a custom java adapter module, which will have below functionalities:
- Read all attachments with their original names
- and store them to sap directory
- This module will require one user input as 'SapDirPath' which is sap directory path location, where attachments will be saved
- This module will be used as Module parameters in 'Receiver File Adapter communication Channel'
- To create this custom java adapter module, please follow link as :
- Sender/Receiver channel configurations are as below:
Sender Mail Adapter Communication Channel:
Receiver File Adapter Communication Channel:
- Here, using File Receiver, one Temp file (Test.dat) will be generated in directory, which will keep on over-writing every time. This file is of no business use, it is used only to complete channel config.
- 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
- This module requires one input which is sap directory path location 'SapDirPath'
- Below Module configurations required in File-Receiver-Channel for custom adapter module access, that require input as FolderPath
- And below is the test screen which depicts how multiple attachments from one unread mail gets extracted and store to sap directory
- For Testing example, below case considered:
- Incoming Mail to (mail-id), which need to be read by interface:
- Below is PI's SXMB_MONI log, in which Mail adapter has forwarded all attachments to receiver channel side
- Below is log of File-Receiver-Channel, in which Custom adapter module's log can be seen
- and at last, screen of sap directory where files are been stored by custom module
[III]. Receiver Determination
- A 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:
[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:
[V]. Sender Agreement
[VI]. Receiver Agreement