Skip to end of metadata
Go to start of metadata

Introduction

There are many APIs to send emails programmatically, but you should prefer CL_BCS class as said in note 190669 for sending lists via SAPconnect using the BCS interface:

As of Release 6.10, we recommend that you no longer use the API1 interface for sending documents. Instead, use the BCS interface.
Compared to the API1 interface, the BCS interface is easier to use since it is no longer required to fill a packing list. In addition, it offers more options (for example, setting any sender).
People have often many issues with the packing list, this parameter is difficult to understand, as binary should be stored in text parameter.

  • Class CL_BCS (the BCS interface), to be used since release 6.10
  • Older function modules:
    • SO_DOCUMENT_SEND_API1
    • SO_NEW_DOCUMENT_ATT_SEND_API1 is now a wrapper of SO_DOCUMENT_SEND_API1, so simply prefer to use SO_DOCUMENT_SEND_API1
    • SO_NEW_DOCUMENT_SEND_API1
    • SO_OBJECT_SEND
    • There are also these function modules that some people use:
      • EFG_GEN_SEND_EMAIL, but it is not released and cannot send to multiple recipients
      • SO_DOCUMENT_REPOSITORY_MANAGER, but it is not released

The email is not sent immediately but collected, either SOST transaction has to be used to release them, or you can call RSCONN01 program.

Moreover, these APIs may also be used to send fax, SMS, or even send message only to Business WorkPlace (SAP integrated office, SBWP transaction).

Before being able to send mails, SAPconnect must be configured, using SCOT transaction.

Documentation

The reference documentations are the blogs of Thomas Jung:

Also, not related to sending, but to receiving mails:

FAQ

What is the simplest code to send an email?

Use this wiki. It is based on CL_BCS, but you don't need to know how object-oriented ABAP works.

How to build lines of more than 255 characters?

With CONTENTS_TXT parameter, lines can have a maximum of 255 characters. You should pass the text as binary as explained in this wiki.
Principle: fill a unique string of characters with lines separated by cl_abap_char_utilities=>cr_lf character, then call function modules SCMS_STRING_TO_XSTRING then SCMS_XSTRING_TO_BINARY (you may also simply call the static method CL_BCS_CONVERT=>STRING_TO_SOLIX) to turn your string into an internal table of type SOLIX_TAB. Pass it to CONTENTS_HEX parameter.

How to prove that the email has been sent?

Use put_in_outbox = 'X' parameter of SO_NEW_DOCUMENT_ATT_SEND_API1, Check if RECEIVER-RETRN_CODE = 0 or not after the function module, Also check if the exception DOCUMENT_NOT_SENT is being raised or not, SCOT customizing INT enter domains to which u can send mail.

What is RFC_MAIL?

This is a C program installed on SAPGUI that you can call to send a simple mail to one person. You cannot enter any subject. This program is not supported by SAP, it could be removed at any time. ABAP statement: CALL FUNCTION 'RFC_MAIL' DESTINATION 'LOCAL_EXEC' EXPORTING user = 'mail@abcde.com' TABLES mail = lt_textitab[].

How to enter tabulation character?

Use CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB. In non-unicode systems before 6.10, use data tab type x value '09' et concatenate 'text' tab 'text2' into text.

How to send an appointment?

Use CL_APPOINTMENT class

Do you want to open a customer message?

First read this!

Troubleshooting

Mails are not sent

When you use the APIs, they are only collected. Either use SOST transaction to send them manually, or from program: submit rsconn01 with mode = 'INT' with output = ' ' and return.
It may be best to schedule a job with program RSCONN02 every 10 minutes when SAP system produces many mails.

Mails are no more sent after migration from 4.6C (or before) to 6.10 (or after, ECC5 or ECC6 for example)

You must add parameter COMMIT_WORK = 'X' when calling SO_NEW_DOCUMENT_SEND_API1

Note 873845 - HTML code in binary form cannot be read

Text document was incorrectly changed from system code page to recipient code page (set in SOST), though it was already in recipient code page. From SAPKP70005, SAPKB62057, SAPKB64016, SO_NEW_DOCUMENT_ATT_SEND_API1 has been changed to wrap SO_DOCUMENT_SEND_API1 exactly. The CONTENTS_HEX parameter should be now used for binary attachments.

Documents are no longer readable after upgrade TO 620

See Note 787418 - Sent documents are not readable after upgrade. Corrected in SAPKB62053, SAPKB64013, SAPKB70003.

The email contains 'P R I N T I N G' instead of 'PRINTING'

Pass email text using CONTENTS_TXT parameter instead of CONTENTS_BIN

The sent appointment doesn't work

There is a recent note: Note 1353329 - iCalendar document that is sent is processed incorrectly

SAP template programs

SAP provides the following programs, which are in fact templates because they can't be executed as is (email is hardcoded for example):

  • BCS_EXAMPLE_1: send a simple text provided as an internal table of text lines to joe.doe@crazy-company.com
  • BCS_EXAMPLE_2: send a simple text provided as an internal table of text lines and text attachment in form of text lines itab to fax DE 09999-123456
  • BCS_EXAMPLE_3: send a simple text provided in an internal table of text lines and an additional note to SY-UNAME
  • BCS_EXAMPLE_4: send a simple text provided in an internal table of text lines recipients are selected in dialogue (default joe.doe@crazy-company.com)
  • BCS_EXAMPLE_5: a simple text provided in an internal table of text lines and an attached MS word document provided in internal table SOLIX_TAB (document retrieval has to be coded) to joe.doe@crazy-company.com
  • BCS_EXAMPLE_6: enter customer, carrier (flight demo data) and email, and generate corresponding FP_TEST_03 adobe form, and send it as attachment to the email
  • SENDLIST_BCS: provided as attachment in SAP Note 190669 - Sending lists using SAPconnect, it uses SO_DOCUMENT_SEND_API1
  • SENDLIST_BCS: provided as attachment in SAP Note 190669 - Sending lists using SAPconnect, it uses CL_BCS
  • ZSSO_DOCUMENT_SEND_API1_46 and ZSSO_DOCUMENT_SEND_API1_610: provided as attachment in SAP Note 609696 - SAPoffice: Error in documentation (SO_DOCUMENT_SEND_API1). There are 2 versions, one for 4.6C, and one for 6.10 and above, the difference between the 2 is only the addition of COMMIT_WORK parameter for 6.10 version. Both call SO_DOCUMENT_SEND_API1.
  • RSWNSENDMAIL1: demo of SO_NEW_DOCUMENT_ATT_SEND_API1

Examples of programs

Many wikis give more or less the same snippet of code, with few variations. Here is a summary which will help you to find quickly what you need.

CL_BCS

As explained above, the simplest generic code to send mails is provided in this wiki: Sending mail with attachment using Object Oriented Approach

Article title

Activatable - Works immediately - It's only a mail demo

TXT or HTML mail's main text

Attachment

Additional info

How to send mail to a distribution list or a group ID

(plus)(plus)(plus)

TXT

One text attachment

 

Sending Appointments or Meeting Requests directly from ABAP

(plus)(plus)(plus)

TXT

ICal text file

It uses CL_APPOINTMENT class to create easily the ICal file

Sending mail with attachment using Object Oriented Approach

(plus)(warning)(plus)

TXT

Any number of binary attachments

Code proposed as a generic easy-to-use function module

SAP Network Blog: Unknown thus unloved?, by Eddy De Clercq

(plus)(warning)(plus)

TXT

None

He wonders why people stick on old function modules, it was a 2006 blog but still relevant. You need to use a function module from another blog and article

ABAP - A Mail to Outlook with SAP Link

(plus)(minus)(plus)

TXT/HTML

None

Shows how to insert an hyperlink to start TRIP transaction from the mail. Needs SICF configuration steps which are not shown here

Send Mail having Multiple Files as Attachment using object oriented technique

(plus)(minus)(plus)

TXT

One text attachment

You need to change the hard-coded email

SDN article: E-MAIL ABAP REPORT LIST OUTPUT IN HTML FORMAT

(plus)(warning)(minus)

HTML

None

Easy-to-use function module which runs a program with variant, retrieves its list, converts it to HTML and sends the mail with this HTML

Publish Webervice in ABAP, Consume Webservice in ABAP and Adobe Flex.

(plus)(warning)(minus)

TXT

None

The goal of the wiki is not to show how to send a mail but it is embedded in a function module in part 1 that can be used standalone. It can only send a simple text to one recipient.

ADOBE - Print form Download Mail pdf

(plus)(minus)(minus)

None

Adobe form output

It uses a non-existing Z* Adobe Form. It must be run in dialog because a dialog asks to save the PDF on presentation server too

SAP ABAP to Outlook Calendar Entry

(minus)(minus)(minus)

TXT

One text attachment of type VCS (Outlook Calendar)

Sends email based on selection screen parameters, program reads infotype 0105 to find the personnel number, User ID and E-mail address

Code to get the content of an attachment in DM and mail it to external email id

(minus)(minus)(minus)

TXT

Zero to many binaries

Binaries come from ECC documents attached (CV01N transaction). Program can't compile directly because of many little syntax errors, but can be corrected easily

SEND ALV GRID AS PDF ATTACHMENT TO SAP INBOX USING CLASSES

(minus)(minus)(minus)

TXT

ALV output in PDF format

The principle is to print ALV to spool directly, convert spool to PDF, and build and send the mail. Can be used in background

Legend:

  • Activatable (plus) means that code can be activated on all NetWeaver solutions (ECC, CRM, SolMan, etc.)
  • Works immediately (plus) means that you don't need to change the program (because of hard-coded email for instance), nor create customizing or data, except SAP flight demo data that you should have initialized on your system (see wiki Flight Data Application - Demo Example for Integration Technologies). If the code is to be created using several manipulations like creating a function module or a global class, it's slow, so only a (warning) is granted.
  • Only a mail demo (plus) means that the article only deals with sending mails

SO_DOCUMENT_SEND_API1

As explained above, this function module is obsolete and complex to use, please use CL_BCS instead.

SO_NEW_DOCUMENT_ATT_SEND_API1

As explained above, this function module is obsolete and complex to use, please use CL_BCS instead.

Documents which only deal with sending email:

Other documents:

SO_NEW_DOCUMENT_SEND_API1

As explained above, this function module is obsolete and complex to use, please use CL_BCS instead.

  • No labels
  1. Guest

    hi,

    tell me about the role of fi Consultant in Implementation - what are roles & responsibilities in implementing the project

  2. Guest

    hi,

    tell me about the role of fi Consultant in Implementation - what are roles & responsibilities in implementing the project

  3. Hello,

    i am looking a way for sending a pdf document as an email body not as an attachment.

    Any ideas?

    Regards.