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: 
Cloud Platform Integration provides Mail adapter that enables you to poll mails from specified mail inbox or send mail to desired mail address. Below table shows the protocols that can be used for mail adapter.
















Adapter Protocol
Sender Mail Adapter IMAP or POP3
Receiver Mail Adapter SMTP


This blog provides you a detailed setup required to poll a mail or trigger a mail from CPI.

First and foremost prerequisite is to have mail domain certificates and mail credentials to be deployed in the tenant. Sometimes it might be possible that the certificates may have been deployed in your tenant, please check whether a valid certificates have been deployed as described below.

Step 1: Go to your tenant WebUI operations view->Connectivity Tests or if you are using eclipse, go to Node explorer and right click on the Tenant->Test Outbound Connection.





Step 2: For Receiver Mail Adapter, click on SMTP and fill in the details as shown below. There is an option for validating the certificates, by enabling the checkbox Validate Server Certificate. On the right hand side, you can see the response providing connection status. If server certificates are invalid, you can download the certificates right here, by clicking on the Download.



Step 3: The sender mail adapter can download e-mails using IMAP or POP3 protocol and access the e-mail body content as well as attachments. Below are few differences between POP3 and IMAP protocol.





















POP3 - Post Office Protocol



IMAP - Internet Messaging Access Protocol


You can use only one computer to check your email (no other devices) You can use multiple computers and devices to check your email
Your mails are stored on the computer that you use Your mails are stored on the server
Sent mail is stored locally on your PC, not on a mail server Sent mail stays on the server so you can see it from any device.


Connectivity tests with IMAP protocol



Connectivity tests with POP3 protocol



Let’s build an IFlow with a scenario to poll mails from an Inbox and extract the attachment of the mail and use XSLT mapping to format and send to another mail box.

IFlow



Components Used































SL. No. COMPONENT DESCRIPTION
1 Sender Channel Mail Sender channel to poll mails from Inbox
2 Script To fetch the attachment
3 XSLT Mapping To format the data.
4 Receiver Channel Mail Receiver channel to send mail


 


  1. Mail Sender Adapter











  1. Script




import com.sap.gateway.ip.core.customdev.util.Message
import java.util.Map
import java.util.Iterator
import javax.activation.DataHandler

def Message processData(Message message) {
Map<String, DataHandler> attachments = message.getAttachments()
if (attachments.isEmpty()) {
throw new Exception ("No content in Attachment")
} else {
Iterator<DataHandler> it = attachments.values().iterator()
DataHandler attachment = it.next()
message.setBody(attachment.getContent())
}
return message
}




  1. XSLT Mapping (optional)




<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Weather Data of
<xsl:value-of select= "concat(current/city/@name, ', ', current/city/country)"/>
</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Condition</th>
<th>Value</th>
</tr>
<xsl:for-each select="/current/*">
<tr>
<td> <xsl:value-of select="translate(substring(name(),1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
<xsl:value-of select="substring(name(), 2)"/></td>
<td><xsl:value-of select="concat(@name, @value, ' ', @unit)"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

 


  1. Mail Receiver Adapter.




Mail attributes:

  1. From: Its mandatory field but a dummy mail id can be provided over here. As there is no validation done on the mail credentials deployed as an artifact with the address provided in the From parameter.

  2. To: It’s mandatory, a valid mail address need to be provided. You can pass this parameter through headers or property (ex: ${header.<Name>} or ${property.<Name>})

  3. Mail Body: Specifies the text of an e-mail message..

  4. Body MIME-Type: Specifies the type of the message body. This type determines how the message is displayed by different user agents.

  5. Body Encoding: Specifies the character encoding (character set) of the message body. The content of the input message will be converted to this encoding, and any character that is not available will be replaced with a question mark ('?'). To ensure that data is passed unmodified, select a Unicode encoding, for example, UTF-8.

  6. Name(under Attachments): Specifies the file name of the attachment.

  7. MIME Type(under Attachments): The Multipurpose Internet Mail Extensions (MIME) type specifies the data format of the e-mail. You can select from the following MIME types: Text/Plain, Text/CSV, Text/HTML, Application/XML, Application/JSON, and Application/Octet-Stream.

  8. Source: Specifies the source of the data. This can be either Body, meaning the body of the input message, or Header, meaning a header of the input message.

  9. Header Name: If the source is Header, this parameter specifies the name of the header that is attached.

  10. Add Message Attachments: Select this option to add all attachments contained in the message exchange to the e-mail.


 

Note: The parameters From, To, Cc, Bcc, Subject, and Mail Body as well as the attachment name, can be dynamically set at run time from message headers or content.

 

Once the IFlow is saved and deployed, the sender mail adapter tries to poll new mails. The mail received at receipt address looks as below.



 

Drawbacks

Well, with the access to the deployed mail credential artifact and to the tenant, it’s possible to send mails to anyone. Therefore, data contained in an e-mail is not reliable without further verification. If the data is too sensitive, its the role of the tenant administrator to provide authorizations to restricted personnel of the team. E-mails can contain malware, such as viruses or Trojan horses, they can cause damage to a receiver system, Since CPI is just acts as a middle ware to connect the systems, its the responsibility of the receiver system to have sufficient protection strategies.

 

Attachment used in the Mail.
<?xml version="1.0" encoding="UTF-8"?>
<current>
<city id="1277333" name="Bangalore">
<coord lon="77.6" lat="12.98"/>
<country>IN</country>
<sun rise="2017-06-06T00:22:28" set="2017-06-06T13:14:20"/>
</city>
<temperature value="303.61" min="303.15" max="304.15" unit="kelvin"/>
<humidity value="48" unit="%"/>
<pressure value="1011" unit="hPa"/>
<wind>
<speed value="4.1" name="Gentle Breeze"/>
<gusts/>
<direction value="290" code="WNW" name="West-northwest"/>
</wind>
<clouds value="40" name="scattered clouds"/>
<visibility value="10000"/>
<precipitation mode="no"/>
<weather number="802" value="scattered clouds" icon="03d"/>
<lastupdate value="2017-06-06T10:00:00"/>
</current>
11 Comments
Labels in this area