Show TOC

Method SENDLocate this document in the navigation structure

Use

The actual work is executed in this method: The objects required for a mail request are created, linked together, and the mail is sent.

Parameters

Parameter Name

Type

Typing

Reference Type

Description

MAIL_ADDRESS

Importing

Type

String

E-mail address

MESSAGES

Changing

Type

CL_BSP_MESSAGES

Message list (optional)

The parameter MESSAGES is defined so that you can catch error situations.

Coding

You need the classes CA_SAPUSER_BCS and CL_CAM_ADDRESS_BCS.

CLASS ca_sapuser_bcs
DEFINITION LOAD.
CLASS cl_cam_address_bcs DEFINITION LOAD.
            

You need the following local variables:

DATA: send_request       TYPE REF TO cl_bcs.
DATA: document           TYPE REF TO cl_document_bcs.
DATA: sender             TYPE REF TO cl_sapuser_bcs.
DATA: recipient          TYPE REF TO if_recipient_bcs.
DATA: exception_info     TYPE REF TO if_os_exception_info,
bcs_exception            TYPE REF TO cx_bcs.
DATA: num_rows           TYPE i.
DATA: textlength         TYPE SO_OBJ_LEN.
            

First create a mail request:

send_request = cl_bcs=>create_persistent( ).
            

Then create the sender of the mail:

* Get sender object
sender = cl_sapuser_bcs=>create( sy-uname ).

* Add sender
CALL METHOD send_request->set_sender
EXPORTING i_sender = sender.
            

You can define your mail address in this Web Application Server in the user maintenance.

The mail can be sent to one or more addresses:

* Create 
data: c_address TYPE ADR6-SMTP_ADDR.
move mail_address to c_address.
recipient = cl_cam_address_bcs=>create_internet_address( c_address ).

* Add recipient with its respective attributes to send request
CALL METHOD send_request->add_recipient
EXPORTING
   i_recipient  = recipient
   i_express    = ' ' 
   i_copy       = ' ' 
   i_blind_copy = ' '.
            

You get the mail address as a string and have to convert it to the required data type.

The mail is sent to one address only without any additional attributes.

The mail is sent to one address only without any additional attributes.

* Send document
CALL METHOD send_request->send( ).
COMMIT WORK.
            

You can now send the mail and write everything to the database.

You can take care of this by embedding the following code in a TRY - CATCH block:

try.
catch cx_bcs into bcs_exception.
if messages is not initial.
messages->add_message
   ( condition = 'mail'
       message =        'Fehler beim Versenden der Mail aufgetreten' ).
"#EC NOTEXT
endif.
exit.
endtry.