Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member


The System Accessor is becoming very useful in Java Mapping. It has opened up new horizon and provided a great level of flexibility to the SAP PI users. My previous blog was to show the database interaction with help of System Accessor. Now here is another usage for sending email. Sending email from Java Mapping and UDF avoids the multi-mapping and so it eventually reduces the complexity of the interface.

Below is the code snippet which can be used in Java Mapping or UDF to send an email:


----------------------------------------------------------------------------------------------------------------------------------

// String Variable to hold the Request XML

String strEMailSysRequest = "";

// Channel Object with Mail Receiver Channel

Channel channelEMailSys = LookupService.getChannel("BC_EMAIL", "EMAIL_R_ COMMON");

// System Accessor Object with Mail Receiver Channel Object

SystemAccessor accessorEMailSys = LookupService.getSystemAccessor(channelEMailSys);

// Convert the Request XML String to Input Stream

InputStream isEMailLookup = new ByteArrayInputStream(strEMailSysRequest.getBytes());

// Create XML Payload object with request input stream

XmlPayload payload = LookupService.getXmlPayload(isEMailLookup);

// Call System Accessor to process the Request data and return the response as XML Payload

XmlPayload result = (XmlPayload) accessorEMailSys.call(payload);

// Convert the XML Payload into Response XML String

String strEMailSysResponse = convertStreamToString(result.getContent());

----------------------------------------------------------------------------------------------------------------------------------

The String strEMailSysRequest need to be prepared as below which is similar to the one which needs to be created using mail package:

<ns2:Mail xmlns:ns2="http://sap.com/xi/XI/Mail/30">

     <Subject>EMail Lookup Test</Subject>

      <From>xyz@abc.com</From>

      <To>pqr@abc.com</To>

      <Content>Hurreyyyyyyyyy, EMail Lookup Test Successful!!! </Content>

</ns2:Mail>

The response XML caputured in strEMailSysResponse was as below:

<xim:MailReceipt xmlns:xim='http://sap.com/xi/XI/Mail/30'>

      <Server>smtp://111.222.333.444:587</Server>

      <Greeting>EMAIL.SERVER.NET Microsoft ESMTP MAIL Service ready at Sat, 18 Jul 2015 18:17:54 +0530</Greeting>

      <Format>XIPAYLOAD</Format>

      <UseMailPackage>true</UseMailPackage>

      <Encoding>binary</Encoding>

     <Subject>EMail Lookup Test</Subject>

      <From>xyz@abc.com</From>

      <To>pqr@abc.com</To>

      <Date>2015-07-18T12:49:36Z</Date>

      <MailID>2.6.0</MailID>

</xim:MailReceipt>

Appreciate your feedback and comments on the System Accessor usages.

3 Comments
Labels in this area