How to Send E-Mails from SAP ERP

DevWorkbench    Saturday August 9th, 2014   

Sending e-mails from SAP ERP is probably the most common development task (or maybe the second common, after building an ALV report). Because of that, let me show you how to do it – I would’ve appreciated it as an ABAP beginner.

SAP ERP considers e-mails a “document”. There are several other types, such as SAPOffice messages (a type of SAP internal mails that can be managed in the transaction SBWP), faxes, X.400 messages and more. All of these documents can be sent (and managed) via a single API that is contained in the function group SOI1.

The correct function module to create an e-mail is SO_NEW_DOCUMENT_SEND_API1. It performs two steps at once: a new document is created in the database, and it is sent to the respective receivers. It’s also possible to do this in two steps; the necessary function modules for this are SO_DOCUMENT_INSERT_API1 and SO_OLD_DOCUMENT_SEND_API1. For now however, let’s focus on the first function module.


Let’s look at the IMPORTING parameters of the function module first. The parameter DOCUMENT_DATA must be supplied with a structure of type SODOCCHGI1. It contains document meta information such as an object name, or the object description. This is important: the object description in field  SODOCCHGI1-OBJ_DESCR will become the title of your e-mail. Another important field is PROC_TYPE, but this is described in another article.

The DOCUMENT_TYPE parameter defines the document class. For e-mails, use the default (“RAW”). Apart from RAW, there are also BIN for binary files and SCR for SAPScript documents.

The other two parameters can be supplied, but the default is usually sufficient. If you don’t want to (or can’t) execute a COMMIT WORK after the function call, then supply the COMMIT_WORK parameter with an X.

Let’s look at the TABLES next. If you want to send a plain text e-mail, the most important parameter is OBJECT_CONTENT. It is a structure with a single element – LINE – that contains the actual body of the e-mail. Fill this table with the text that should go into your mail.

The table parameters OBJECT_HEADEROBJECT_PARA and OBJECT_PARB are only relevant for executable documents (again, this is described in another post). However of course, you need to fill the RECEIVERS table, which is a structure of type SOMLRECI1. The important fields are:

  • SOMLRECI1-RECEIVER: fill this with an SAP user name – if it has an e-mail address maintained, the e-mail will be sent there. You can also put an e-mail address here directly.
  • SOMLRECI1-REC_TYPE: if you put an SAP user name in the RECEIVER field, this must contain an “B”. If you put a plain e-mail address, this parameter must be filled with “U”.

And that’s it already! You can now execute the function module and send e-mails to your recipients. Find out on the next page how you can monitor the sending process of your mails.