Handling Attachments in Mail to File Scenario using Payload Swap Bean
In a SAP – PI, adapters converts messages from the PI Protocol (SOAP with attachments over HTTP) to the respective protocol “understandable” by application system, and vice-verse thus enabling the compatibility between the PI Integration Server and an application system.
There are many adapters categorized in SAP-PI like Mail Adapter is categorized to Technical Adapter which enables you to send PI messages to mail server or create PI messages from incoming mails. Also File Adapter which falls again in Technical category of adapters, used to read and write the files at the OS level. The OS level directory must be accessible by the service user of Adapter engine, with the appropriate read-write permission.
Scenario
User sends the business document as an attachment in a mail to the desired mail server from where it is been pulled and processed in PI. Once processing is done the message is sent the target application system.
Design overview
Mail Adapter will pull mail (containing attachment) from the mail server using Transport Protocol IMAP4.The content of the attachment file is converted to an XML message (SOAP Message) through the adapter. The incoming SOAP document would undergo mapping before being converted to the output structure and than this message is send to the File Adapter for sending the File to the desired path in target system.
ESR Objects:-
Note: While configuring Operational Mapping we have a check box “Read Attachment”. Checking this option we will deal attachments in mapping and thus limiting us to use PayloadSwapBean. As in our scenario we are dealing with PayloadSwapBean that’s way we left this “Read Attachment” option Unchecked.
ID Objects:-
Parameters for Sender Communication Channel :
syntax for URL will be: URL: pops://MailServerPath
the syntax for URL will be: URL: imaps://MailServerPath/PersonalFolderName 2) Message Protocol: Two types of Message Protocols are present:
content of the RFC822 mail message which is the standard one.
information is also used for the e-mail. If mail package format is not used, the header information is obtained from the adapter
configuration.
3) Configure User Authentication: Checking this box will give you the fields like Username and Password which is required just for authentication while connection to the mail server. This username and password is of the user owing the mail address to which the mail is to be sent or from which mail address is the mail to be pulled.
4) Delete Message Once Read: By checking this property, you need to give the folder name in which you want the mail to be pushed once it is read i.e. once the mail is read it will be deleted from the original folder and is moved to the given folder.
5) Mail Attributes:
For Sender Configuration, it doesn’t play any role.
6) Security Parameter: If you have assigned the receiver agreement a communication channel, you can specify security settings for message security. You can digitally sign and encrypt e-mails. Here, message security is based on the S/MIME internet standard (Secure Multipurpose Internet Mail Extension). The S/MIME implementation is based on the Cryptographic Message Syntax (CMS) standard, RFC 3852. For Sender this functionality is not in use.
7) Processing Parameters:
😎 Module Parameter: PayloadSwapBean moduleis used to replace the application payload of the XI message that contains the business data with another payload that is appended to the XI message as an attachment.
To ensure that the attachment that is to replace the application payload can be found, we must now specify a parameter from the MIME header.
● swap.keyName
Enter a payload attribute such as payload-name or payload-description, or an attribute from the MIME header such as content-Disposition, content-description, and so on.
● swap.keyValue
Enter the value that the attribute is to have. The MIME headers of the payloads are searched in order and the system takes the first payload that meets the criteria. This payload is swapped with the application payload.
Note: Using PayloadSwapBean we can not handle multiple attachments. Thus limits us to use when we are dealing with only one attachment.
To Test the scenario send the mail in your mailbox as an attached file as shown in screen shot below.
Since we are using IMAP4 as a Transport Protocol so the Mail Adapter will ping to the Mail server, mail will be marked as read from the personal Folder (Mail Adapter) as shown below.
Input File: Input.xml
1) SXMB_MONI:
2) Runtime Work Bench:
Once the processing is done successfully the output file will be created on target path (/var/XEF/data/Mail)
Output File: Output.xml
General Errors regarding this scenario:
1) ConnectException: A remote host refused an attempted connects operation.
Reason: This happens while configuring the mail communication channel in URL field
we will not specify the Transport protocol we are using.
URL: MailServerPath/
Correction: Always specify the used Transport protocol in URL field.
URL: imaps://MailServerPath/PersonalFolderName
2) Getting Synchronous Messages in SXBI_MONI.
Reason: Using “Best Effort” in Quality of Service while configuring sender
Communication Channel.
Correction: Update Quality of Services to “Exactly Once”
3) Parameter Value Issue: Mapping is not been processed.
Reason: Using different File name than the original attached filename in mail.
Correction: The parameter value for filename should always be same as the file name we
are getting as an attachment in a mail.