In this article we shall discuss the configuration of SAP XI Mail Adapter on the receiver side. The receiver mail adapter resides on the J2EE stack and converts the XI messages into emails and transfers them to email server or in simple words sends them as emails to intended recipient(s).
The adapter supports SMTP as well as IMPA4 protocol. Message protocol provides two options, namely XIALL and XIPAYLOAD. In the former entire SOAP message is sent as an attachment in mail along with the payload while in the latter only the message payload is sent.
Configuring the Receiver Mail Adapter
Let’s say you want to send incoming XML message as an email. The mail adapter provides two options – one using the mail package and one without using mail package. When you do not use mail package you have to provide the email header details (like To and From addresses, Subject line etc) in the adapter itself. There is no restriction on the XML message format or namespace.
However, when you use mail package, you have to adhere to a specific format of the source XML.
The figure above on the left shows a typical message structure that should be used while configuring receiver mail adapter with mail package. The Message Type must be named as ‘Mail
’ and it must be present under the Namespace ‘http://sap.com/xi/XI/Mail/30’
. Your message is bound to fail in adapter engine if this is not adhered to. This helps you to dynamically set email parameters like sender, receiver mail subject etc.
The URL of the mail server should be specified as shown below depending on whether you use SMTP or IMAP4.
smtp://EmailServer
or imap://EmailServer/UserInbox
If your server required User Authentication, you can specify the same while configuring the adapter. If you want to request a delivery receipt, check the ‘Send Delivery Status Notification’ checkbox. The delivery receipt is delivered to the email address specified in the ‘To’ field. base64 content encoding is possible. The figure on the right shows a typical configuration of the receiver mail adapter.
The output using the mail package is as shown below:
If you do not use mail package, the XI message will be sent to the static addresses as specified in the receiver mail adapter configuration. A typical output is shown below:
If you use XIALL as Message Protocol, the entire SOAP message is sent as an email attachment along with payload as shown below.
The first attachment in the email message shown above is the SOAP message while the second attachment is the actual payload.
As with any other J2EE adapter, you can enhance the adapter further using the adapter modules which can be specified in the module tab of the communication channel. This article discussed the simplest way to work with mail receiver adapter in order to send mails from XI server.
Please let me know , how would i configure to get part of the incoming XML msges in the e-Mail body and part as attachment.
Hi Sundar,
I guess for this you need to create and use ABAP or Java mapping. Then u can use custom adapter modules to further add the message as attachment.
Hi ,
Here while using the receiver mail adapter, either the content is coming dynamically or the attachment is coming. But I need both the attachement and the dynamic content. Please suggest how it will work out .
Regards ,
Hemanthika
Hi Hemanthika,
You might need to use adapter modules to accomplish this. Try using PayloadSwapBean module to swap the application payload with one of the attachments – see this link for details.
If this does not help, check my email. I have sent you a how to guide.
Regards,
Riyaz
Have you tried with selecting both ‘Use Mail Package’ and ‘Keep Attachments’ checkboxes? If it does not work, then go for adapter modules as suggested above.
Hi Gents,
I’ve been struggeling alot to acheive my requirement which is the following:
File adapetr picks up one file, and this file should be send as BOTH ( mail body and part of it i wanna create an attachment)
so simply i want create a body and attachment out of one message
i am using the Mail package..and i was successfully able to send emails either as an attachment ( the whole content becomes as attachment ) or as a body
But i couldn’t find a way where you can send both at the same time in one email
I tried to use all the adapter modules that you mentioned
the SwapBeans, and the MessageTransformBean
with no luck again same result
i can send email either with body AS and attachment
or send the same payload just as a body with no attachment
i also checked and Uncheked the Keep attachment in the adapter configuration but no luck
Please if you can help me in how to send an email with a body and with attachment i would really appreciate it
Regards
Tarek
Hi Tarek & Hemanthika,
Please go thru – https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/6321.
Let me know if it helps.
Hi…
I have done the file to mail scenario. In receiver side i have used the smtp adapter.I have followed the steps which u have specified. While executing it is showing the below error.
MP: Exception caught with cause com.sap.aii.af.ra.ms.api.RecoverableException: java.net.UnknownHostException: 172.16.186.216.corp.satyam.ad
Delivery of the message to the application using connection Mail_http://sap.com/xi/XI/System failed, due to: com.sap.aii.af.ra.ms.api.RecoverableException: java.net.UnknownHostException: 172.16.186.216.corp.satyam.ad.
Hi Leela,
Please check the URL for the smtp server that you have specified in the mail receiver adapter. It should be the complete hostname of your email smtp server. If you are using microsoft exchange server, you can find the hostname in the email account properties of your Outlook.
If specifying hostname results in error, specify corresponding IP address. You can find out IP address by pinging the hostname via command prompt.
Also make sure you provide the URL using correct syntax. For smtp it is –
smtp://hostname or for IP address something like smtp://10.25.123.456
Regards,
Riyaz
Hi Riyaz,
To avoid missing out important parameters, etc, is the mailpackage message structure downloadable, and if ‘yes’ where?
Kind regards,
Reuben.
Hi Reuben,
You can download the SAP note 748024 from SAP Marketplace. The Schema file is attached with this note.
Regards,
Riyaz
Hi Riyaz,
You have mentioned that “…Message Type must be named as ‘Mail’ and it must be present under the Namespace ‘http://sap.com/xi/XI/Mail/30’…”.
**Q**: in case i’m using XI 7.0, what would be the case then? (e.g., is the main cocept is still the same? what should be the namespace name?)
Hi,
This does not change for PI 7.0. You need to use the same namespace and message type.
Regards,
Riyaz
Hi Riyaz
i am using a scenarion with fileadapter + mailpackage and want to send an email with a pdf as a attachement.
in sxmb_moni it looks ok is see payload maindocument and te pdf file.
the mail however is containing 2 attachments with name untitled.xml and untitled.pdf.
what i want is that the original filename is placed in the attachment name.
this name is shown in sxmb_moni.
any suggestions.
your article is great, thanks
Hi Peter,
I would suggest that you can consider using adapter modules like DynamicConfigurationBean. I guess it allows you to update the name of the file.
You can set Adapter specific message attributes for Filename in the sender adapter and then use ASMAs in receiver adapter or use DynamicConfigurationBean.
Also go thru this article if you prefer using Java mapping.
Regards,
Riyaz
Apologies for the late reply. But thank you!
Hi Riyaz,
I have a scenario where FILE to EMAIL with PDF as an attachment; I also need to send to have Email body with some text. For this i have tried using Mail Package then i wont be receiving any attachment. If I use both Mail package + Keep attachments i do not see any attachments in mail.
Let me know the possible ways that can used in the current scenario where i need to send pdf attachment along with messsage body.
Thanks in advance,
Swetha.
Hi Swetha,
You can try this approach or make use of adapter modules like PayloadSwapBean, MessageTransformBean.
Riyaz
Hi Riyaz,.
My scenario works perfectly. I’m Xi Payload and sending the information in the mail package (using the mail package downloaded from SAP). What I would like to do is reformat the message to make it a little more readable. Is it possible to send a message as rich text, insert carriage returns and bold or underline certain parts of the content?
Your help is appreciated.
Hi Rob,
Try to modify the content type and Content-Disposition to achieve this. See Stefan’s article for details.
Hi,
I m doing file to mail scenario.
I followed a blog on sdn tv blog to create message type.
I need screenshots or help about source message type. I think for source message type namespace can be different and namespace for target message type would be as you mentioned above (downloaded from sap note)
i have problems in message mapping as i want to send a file (which is created due to to rfc to file scenario).
waiting for response
regards
ateeq
It does not matter how the source XML is structured. Only you need to ensure that the target XML is populated correctly using the appropriate mapping program.
I wanted to send an email with custom Body message and no attachment, I am not doing any mapping for this, can you please tell what option should I choose?
You can build up an email message with a custom body easily using a Java mapping.
We are trying to develope an interface in SAP PI 7.0/7.1 where we take a Purchase Order, create an HTML body to be placed into the email, while also creating a file to be attached. Thus, the HTML body contains a nice looking copy of the Purchase Order, while the attachment contains a few fields simply in a flat file. Any ideas?
Chris, you can easily do this with the help of Java mapping. Have a look at Stefan’s article to get an idea. If you need more help, just let me know.
Hi Riyaz, I’m using Email receiver adapter to send email with attachment. My problem is everytime i’ve to send the dynamic filename in the attached file. Everytime I mail to my Vendor, the filename in the attachment must be different. Is it possible to achieve this without adding custom Adapter Module in the Email adapter?
Thanks.
How are you generating the attachment? If you use Java mapping, you can have full control over the attachment name. You can set the attachment name in the Java mapping that generates the email message.
Riyaz, Can you please let me know how to achieve this through Java Mapping?
Thanks in advance.
Have a look at Stefan’s article to get an idea. If you need more help, just let me know. See this article for basics of Java mapping.
Hi Riyaz, Good Morning. Thanks for your valuable guidance for my above query. And now i’m able to achieve dynamic sub with dynamic filename in the attachment. But i’ve only one issue. Iin Stefan’s blog Java code if I add Cc and Bcc, then i’m not even getting the E-mail. I also tried with only From and Cc deleting the “To”; even then i’m not getting the email. It works only if i’ve From and To. Can you throw some light on this?
Thanks in advance.
It could be due to conflict with your message type. Check the mail message type you are using and make sure all the mandatory fields like From, To are correctly populated by the Java mapping program. You can check the error messages in the receiver channel monitor using Runtime Workbench to see why the email was not sent out.
Hi Riyaz,
I want to add following parameters :
Content-Class:InfoPathForm.InfoPath
Message-Class:IPM.InfoPathForm.InfoPath
to the header of the outgoing email.
I have tried to use the Variable Headers(under the Adapter specific Messages Atrributes) in the receiver communication channel.
but it did not work.
Can you please suggest if it possible to add Custom attributes to the Email header.
Thanks,
-Kaushik
You can consider using a Java mapping program to generate the target email message. You can create the header and body as per your requirements.
Dear Riyaz,
Dear Sir,
I read your blog and put an insight through your website.I realized that you are the 1 who can help me.I got an assignment.And I am sure that you will help me.I shall be highly thankful to you for this kind act.
Details:
Convert HTML/CSS/JSP documents into PDF files using an API called Flying Saucer.After that convert PDF file into bytes so that it could be attached on email’s body.This all is done in Eclipse and I need the runnable coding.
Thanks & Regards,
Manish
You can send me the code on
er_manish89@rediffmail.com
I appreciate your effort and the quality of the information you provide. It’s really helpfully for me to write content in my assignment. Thanks.
I am looking for a solution to trigger email upon completion of file transfer using xi 7.0 adapter engine
Hi.. the article is good. I would like to about more about the “Content-Type” used here. What is content type and why we use it here…
For instance, in our adapter we used
application/xml;charset=”utf-8″;name=”
would like to know what is that (application/xml:charset=”utf-8″;name=”) denotes here.