Skip to Content
Author's profile photo Lena Grothaus

Extract Incoming Payment Advices Directly from your Email Inbox

With SAP S/4HANA 1809, you can use an email integration functionality with SAP Cash Application, to fetch payment advices from your inbox and then extract its relevant information with machine learning and computer vision.

So far, you had to upload your payment advices manually in the Fiori app Manage Payment Advices. For that, you first had to identify the emails containing payment advice information.

This is how you can make your life easier now:


  • You have acquired the license for SAP Cash Application.
  • You have enabled the machine learning service Payment Advice Extraction as part of SAP Cash Application on your S/4HANA system (via the customizing activity Enable Machine Learning for Payment Advices).
  • You have access to the oData service <hostname>/sap/opu/odata/sap/FAR_MANAGE_PAYMENT_ADVICES_SRV/PaymentAdviceFileSet/ running on your system.

Create a simple connector to read the e-mails and post them to the oData service

In this example the connector was created in Python, however, you can use other languages as well.

Sample code:

from exchangelib import DELEGATE, Account, Credentials, Configuration, UTC_NOW
from datetime import timedelta
import requests
import time

def upload_attachment(attachment):

headers = dict()
headers['x-csrf-token'] = 'Fetch'
headers['Authorization'] = 'Basic abc123'
headers['Content-Type'] = 'application/pdf'

fetch_result = requests.head('http://s4hanaserver:port/sap/opu/odata/sap/FAR_MANAGE_PAYMENT_ADVICES_SRV/', headers=headers)

if fetch_result.status_code == 200:
del headers['x-csrf-token']
headers['x-csrf-token'] = fetch_result.headers['x-csrf-token']
headers['slug'] = 'companycode=1010;filename=' +
files = {'file': (, attachment.content)}

upload_result ='http://s4hanaserver:port/sap/opu/odata/sap/FAR_MANAGE_PAYMENT_ADVICES_SRV/PaymentAdviceFil Set/', headers=headers, files=files, cookies=fetch_result.cookies)

if upload_result.status_code == 201:
print('Document uploaded to the server successfully')
print('Error: ' + upload_result.text)
print('Error when getting CSRF token: {} {}'.format(fetch_result.status_code, fetch_result.text))

credentials = Credentials(username=EXCHANGE_USER, password=EXCHANGE_PASSWORD)
config = Configuration(server=EXCHANGE_SERVER, credentials=credentials)
account = Account(primary_smtp_address='', config=config, autodiscover=False, access_type=DELEGATE)

while True:
last_minute = UTC_NOW() - timedelta(minutes=1)
mails = account.inbox.filter(datetime_received__gte=last_minute)  # Filter by a date range

for mail in mails:
for attachment in mail.attachments:



  • The Python library exchangelib is used, to simplify the connection from Python to the Microsoft Exchange Server using the Exchange Web Services (EWS) protocol.
  • In line 37, an infinite loop reads every new e-mail received in the last 60 seconds.
  • In case an e-mail contains an attachment in PDF format, the function upload_attachment is called, to upload the document to the oData service.
  • During the upload_attachment execution, to authenticate against the S/4HANA system, a HEAD request to the oData service is triggered, including x-csrf-token = Fetch and the encoded user and password of the backend system in the format Authorization = Basic <encoded user and password combination> as part of the header (lines 10 – 18).
  • A POST request to the oData service is triggered, including the x-csrf-token received, and a new header attribute called slug in the format companycode=XXXX;filename=YYYY.pdf. This defines the company code and the file name to be used in the S/4HANA system. As a result, the http code 201 indicates that the file was uploaded successfully.

Connect an inbox to the application via the connector

  1. Set up a shared inbox for e-mails that include payment advice documents as PDF attachments.
  2. Create a generic user for the app Manage Payment Advices, to be the default owner of all e-mails sent to the shared inbox.
  3. Follow the steps in the customizing activity Enable E-Mail Integration. Note: The user must be the same used to call the oData service.
  4. Run your connector.
  5. Send an e-mail with an attached payment advice in PDF format to the shared inbox.
  6. In the app, select Load from Email to have the latest payment advices from your inbox directly displayed under the Confirmation Pending


The extracted information from the payment advice is displayed in the application.

This possibility aims to further automate your process of cash application as part of the order-to-cash scenario in accounts receivable accounting, by reducing one more manual, tedious, and error-prone step.



This is not an out-of-the-box solution delivered and supported by SAP. However, it is an example of how to easily enhance your automation journey with SAP Cash Application.

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Xenia Witte
      Xenia Witte


      Thanks for this, very helpful.

      You mentioned the below:

      'So far, you had to upload your payment advices manually in the Fiori app Manage Payment Advices.'

      We have a scenario where the payment advices come in an excel format and contain up to 1000 line items. From what I understand the extract from the email currently only picks up a pdf format.

      You above comment mentions previously uploading manually. Does this functionality provide for uploading and excel format manually?

      If not, is there a process to load mass line items into a customer remittance advise on S4H



      Kind Regards


      Author's profile photo Kevin Lee
      Kevin Lee

      Hi Xenia,

      Excel extraction was added May 2020 and is available in Cloud Edition and OP2020.


      Author's profile photo Siegfried Weber
      Siegfried Weber

      Hi Xenia,
      is there a How-To-Paper for using "Excel-Payment-Advices" in OP Landscape?