We have earlier discussed how to configure receiver mail adapter to be able to send emails from SAP XI. In this article, let us understand the configuration of Sender Mail Adapter. Sender Mail Adapter is used to collect emails from an email server and convert them to XML messages so as to process them in XI Integration Engine.
Configuring the Sender Mail Adapter
The adapter supports POP3 as well as IMAP4 protocols. You need to specify the connection parameters for the mail server. Specify the Mail server URLs depending upon the transport protocol (POP2 or IMPA4) in the format given below:
pop://EmailServer
or imap://EmailServer/UserInbox
Select the ‘Use Mail package’ indicator if you want to receive the email along with header information (like sender, receiver, subject etc) as payload. If you don’t check this box, you will only receive email content as your payload. You can specify the content encoding as required. If you do not choose any, the message will be transferred as it is.
If you want to preserve the attachments, select the ‘Keep Attachments’ checkbox. All the three Quality of Service (BE, EO, EOIO) are supported. Specify QoS as per your scenario. Provide the name and namespace of the outbound interface from Integration Repository that should handle the further processing of the converted XML message and you are done.
Specify the poll interval i.e. the time interval between two attempts by XI to check for any new messages. Once active, the adapter will start polling the Email Server. The adjoining figure shows a typical configuration of Sender Mail Adapter.
Say your email inbox receives an email shown below.
Once XI polls the server, the email will be picked up and processed by the adapter engine. The figure below shows the resulting XML payload after processing by the adapter engine.
Thus, we are done with configuration of sender mail adapter. If the email is received in rich-text or HTML format the same is sent in the form of a SOAP attachment along with the message payload. We can see this using transaction SXMB_MONI or SXI_MONITOR.
Also Read:
Hi ,
it is excellent stuff , i have configured the sender adapter as you shown above but i am getting the error “exception caught during processing mail message; java.net.ConnectException: Connection timed out: connect” in the sender adapter.
In Aunthentication Method i have given as my maild and password , is it correct?
Can you please tell what should be done
Thanks and Rgds,
Kamal
Hi Kamal,
Thanks for the compliments.
To resolve this error, make sure that your email server is accessible and supports pop access and that you are using the correct URL. You can confirm the URL from your outlook properties or whichever email client you are using. If the URL has hostname in it, try by replacing the hostname with its corresponding IP address. You can ping the server hostname using command prompt to find its IP address.
Also, if you are using Mail Package, you must use the namespace http://sap.com/xi/XI/Mail/30. If its not available, you can download it from SAP service marketplace or manually create one.
Let me know if this helps.
Regards,
Riyaz
Hi Riyaz,
Thanks for your Valuable Comments, I have implement the same it is working fine for me , i need to Read an attachment from the mail, now i am able to get a mail , in SXMB Moni i am getting the Payload with attachment(PDF), I have a create a module to convert that PDF to XML(Module is working fine in file to file sceneraio) . My doubt is should i need to use Payload Swap Bean Module also , because in sap help said i Select Keep Attachments, we need to use that one.
Can you please tell me how to proceed futher
Hi Riyaz,
Thanks for your Valuable Comments, I have implement the same it is working fine for me , i need to Read an attachment from the mail, now i am able to get a mail , in SXMB Moni i am getting the Payload with attachment(PDF), I have a create a module to convert that PDF to XML(Module is working fine in file to file sceneraio) . My doubt is should i need to use Payload Swap Bean Module also , because in sap help said i Select Keep Attachments, we need to use that one.
Can you please tell me how to proceed futher
Thanks
Kamal
Hi Kamal,
I havent personally worked on adapter modules. However, if I find some useful information, I will pass it on to you.
Regards,
Riyaz
Hi Friend,
doubt in file to rfc to mail scenario .can you please send any screen shot for this requirement.
Regards,
Ravi.S
Hi,
For RFC Sender Adapter – see this – https://www.riyaz.net/?p=42
For Mail Receiver Adapter – see this – https://www.riyaz.net/?p=83
Regards,
Riyaz
Hi Riyaz,
Thanks for the help.One small doubt after getting File Responce from xi server iam connceting mail adapter.
Step 1 : send is file adapter (File Request)
step 2 : receiver is RFC (Bapi fm in R/3 side)
step 3 : after creating saleorder iam getting information from xi through File Responce.
Doubt : after getting responce from xi
sender is file responce file adaptre
receiver is mail adapter right ?
Regards,
Ravi.S
Hi Ravi,
If you want to use a BAPI/RFC at the receiver side, you will require an RFC receiver adapter and not the mail adapter. See for details.
Regards,
Riyaz
Dear Riyaz,
I am having one doubt. Could u please help me in this issue.
In a file to file scenario, the input file will be picked from a directory location and after processing output file will be placed in the output directory location specified in the receiver communication channel.
In the sender communication channel for the scenario mentioned above, if the processing mode is given as delete, the input file will be delete as soon as the file was successfully read by the adapter, but this will not ensure that the file processing is complete and the output file is being created.
If we have a scenario in such as way that the input file should be deleted from the input folder only if the complete process is successful and the output is generated. how can we achieve this functionality?. send me your reply as soon as possible.
Leela,
This option is currently not supported by XI. No idea if it will be supported in future releases or not. This is because if the polling interval is shorter than the time required to process the file completely, there is a possibility of the file being picked up twice leading to duplication errors.
What you can instead do is, set the Processing mode to Archive and specify an Archive directory different from that of the source. So once the file is processed, it will be deleted from source and placed in the Archive directory.
If you do not want to retain the archived files, you can schedule a daily/weekly job to clear the Archive folder (after ensuring that the files in error are not deleted).
Regards,
Riyaz
hi Riyaz,
I keep getting this error in my Communication Channel monitoring
exception caught during processing mail message; java.lang.NullPointerException
I can’t figure out why.
Do I need to use Mail Package?
I don’t have http://sap.com/xi/XI/Mail/30 in IR.
My POP URL and authentication are correct.
I can’t get any more details on this error
Hi Bill,
Sorry for delayed response.
Try using the namespace http://sap.com/xi/XI/Mail/30. If its not available, you can download it from SAP service marketplace or manually create one.
Riyaz
Hi Riyaz,
I have the same problem that Bill.
My scenario is Mail–>XI–>Proxy(R/3).
The sender mail adapter checks the e-mail box and procces into XI.
I’m getting the following error in the CC:
“exception caught during processing mail message, java.lang.ArrayIndexOutOfBoundsException 0 > = 0”
But, this error is only present when the client try to sent the e-mail data, If i resend the same e-mail manually it works perfectly ( Which led me to think that the CC configuration is correct ).
I’m not ruling out any outlook issue.
Do you guys have experiencied this kind of issue?
Thanks.
Hi Federico,
Check for blank/null inputs if you are using any additional adapter modules or Java mapping. Also, check string conversion functions used in message mapping for any blank/null inputs.
Hi Riyaz,
If it is a distributed mail address any other settings are required?
Thanks
Ramesh
HI Ramesh,
If you mean a distribution list email address, same settings should work. But there has to be a common mailbox to read from and appropriate logon creadentials (for sender mail adapter).
Hi,
I have a message error when configure sender channel:
exception caught during processing mail message; java.net.SocketException: Connection timed out:could be due to invalid address
Can you help me?
Hi,
Make sure you are using a correct server address and correct username/password to retrieve emails from the mailbox.
Hi Riyaz,
My mail server was not responding on port 110, but now this problem is solved.
Thanks a lot.
Edson
Hi Riyaz,
I am doing a file – RFC -file scenario and facing the error:
Error: java.lang.NullPointerException
thanks,
jaya
Hi Riyaz,
I configured sender mail adapter with correct URL and User Login Credentials and POP3 protocol..
URL : POP://mail.company.com
Also XML comes as attachment hence using payloadswapbean module..
Am facing the following issue :
“exception caught during processing mail message; java.io.IOException: unexpected user response; read -ERR Command is not valid in this state.”
Am using 2 levels of mapping in Operation mapping : Step 1) XSLT mapping and Step 2) Message mapping. Have you experienced this error. Your reply would be of great help.
Thanks
Padmini
Padmini,
Where are you seeing this error? In Communication Channel monitor or in SXMB_MONI?
Check the step by step adapter log in Communication channel monitor to see if there are any issues polling the mail server.
Hi Riyaz,
I have a scenario where I’d need to have PI receive an e-mail, take its attachment and store it on the file system unchanged. How would I go about that?
Thanks,
Patrick
Patrick,
You can use the PayloadSwapBean module in the sender mail adapter. This is used to swap the payload with attachment. After that you can pass on the new payload to the file adapter.
Hi Riyaz,
Thanks for the hint. Would that also work with say a PDF file?
Thanks,
Patrick
Yes…it should work with any format as such. Make sure you dont use mapping program. Simply pass the payload directly to file adapter using a dummy (non-existent) interface.
Alternatively, if you are on PI 7.1+, the new Java API allows you to handle attachments efficiently via Java Mapping. Maybe you want to explore that.
Thank You Riyaz,
so far Your instructions have been very helpful. For me there is one question left, whis is:
wich next steps would be required to finally get a document very similar to the resulting XML-payload above, except that instead of the message_ID the message itself (e.g a base64encoded PDF-Document) goes in a field accordingly called message ?
Best Regards
HelmutK
You already have the message body in the field. However, if you want to modify the message further say base64 encoding, you can always do that in a custom adapter module or in a Java mapping program.
I have a scenario where I’d need to have PI receive an e-mail, take its attachment and store it on the file system unchanged. How would I go about that?
Going further with the above question, I have a requirement where the filename that is to be stored on the file system should be the same as the attachment file name. In the sender mail adapter there is no place where I can set the filename attribute of the attachment. How do I go about ensuring the filename archived is the same name as the attachment?
-Archana.
You can use the PayloadSwapBean module in the sender mail adapter. This is used to swap the payload with attachment. After that you can pass on the new payload to the file adapter where you can set or retain the original filename as desired. Use the ASMAs to read the filename in file adapter if necessary.
Hi Riyaz,
I have used the PayloadSwapBean to swap payload with the attachment and that works. What I am not able to figure out or access is the Name of the attachment. I can see the name of the attachment in the message monitor under Payloads “MailAttachment-1(text/xml;name=”XYZ_123_20100804.xml”) but how do I get access to the attachment name XYZ_123_20100804.xml? I cannot seem to capture this name anywhere and send it to a receiver file adapter with the same name. Can you describe in detail how do you go about doing this?
Thanks,
Archana.
You can try using ASMAs in the receiver file adapter. To do this, select the checkbox against File Name in the Adapter Specific Message Attributes in receiver file adapter. Save, activate and test your scenario.
If this does not work yet, then you need to use a Java mapping program that reads the attachment name and adds it to the Dynamic Configuration section of SOAP header. You can write the filename to Dynamic Configuration using message.setMessageProperty() method. Select ASMA in advanced properties and select File Name checkbox in the receiver adapter.
Alternatively you can do the same thing in an adapter module if you like.
Hi Riyaz,
I have same requirement as Archana but I have multiple attachments in one email. I want to have files with same names as attachments names on target sides. Is payloadswapbean possible to use in case of multiple attachments? If not, Can you please suggest possible solution ?
Thanks in advance.
Ankit
I have a scenario where in need to read mails and map the content(not the subject or sender or the receiver) of the email to an IDOC. Can you pelase suggest how we can achieve that? I have tried to use message protocol XIALL, but have not made much progess.
Hi Riyaz,
we are getting an error in PI during IDOC transmission to XXXX and XXXX. This error occurs irrespective of the IDOC type and interface. It looks like a System error as all the below messages are related to java.lang.NullPointerException. Could you please check?
Error Log
IDoc: Adding control record to payload failed due to Error during transform: java.lang.NullPointerException: while trying to invoke the method java.lang.String.length() of an object loaded from local variable chars
MP: exception caught with message Error during transform: java.lang.NullPointerException: while trying to invoke the method java.lang.String.length() of an object loaded from local variable ‘chars’
Exception caught by adapter framework: Error during transform: java.lang.NullPointerException: while trying to invoke the method java.lang.String.length() of an object loaded from local variable ‘chars’
Transmitting the message to endpoint using connection SFTP_http://sap.com/xi/XI/SFTP failed, due to: com.sap.engine.interfaces.messaging.api.exception.MessagingException: java.lang.Exception: Error during transform: java.lang.NullPointerException: while trying to invoke the method java.lang.String.length() of an object loaded from local variable ‘chars’
PI -7.31 Java only Back end systems -ECC
Thanks,
Sankr