Menu

Change the SAP Sender Email Address in ERP

DevWorkbench    Friday April 24th, 2015   

We sometimes want to control which email address is displayed when we send an email from SAP. Unfortunately, the function module SO_NEW_DOCUMENT_SEND_API1 uses the current user’s email address by default. Here’s a way to change this behaviour and set the SAP sender email address manually.

When we analyze the function module interface of SO_NEW_DOCUMENT_SEND_API1, there is no way to input a sender email address. This is on purpose, as SAP normally is supposed to use the current user’s email address maintained in SU01.

However, the email address is determined very early in the send process. SO_NEW_DOCUMENT_SEND_API1 calls SO_OBJECT_SEND, which does have input parameters for the sender mail address, namely ORIGINATOR and ORIGINATOR_TYPE. To expose these parameters, a few steps are enough:

  1. Make a copy of the function module SO_NEW_DOCUMENT_SEND_API1.
  2. Modify the new function module Z_SO_NEW_DOCUMENT_SEND_API1 to expose the parameters in its interface and supply them to SO_OBJECT_SEND.
  3. Modify the coding of the new function module slightly so the integration with function group SOI1 still works.

Step 3 is a bit tricky, but can be done quite easily if you know how. This is how to call the new function module to manually set the sender email address.

CALL FUNCTION 'Z_SO_NEW_DOCUMENT_SEND_API1'
 EXPORTING
   document_data = ls_docdata
   originator = 'senderemail@example.com'
   originator_type = 'U' "This needs to be 'U'
 TABLES
   object_content = lt_content
   receivers = lt_receiv
 EXCEPTIONS
   too_many_receivers = 1
   document_not_sent = 2
   document_type_not_exist = 3
   operation_no_authorization = 4
   parameter_error = 5
   x_error = 6
   enqueue_error = 7
   others = 8.

Simply supply the parameters ORIGINATOR and ORIGINATOR_TYPE. ORIGINATOR will contain the email address you want to use as sender. ORIGINATOR_TYPE must be set to “U”.

Please find the complete coding of the new function module on the following page.