Emailversand mit der Klasse CL_DOCUMENT_BCS

*&———————————————————————*
*&      Form  send_email
*&———————————————————————*
*       text
*———————————————————————-*
FORM SEND_EMAIL.

* (1) Create email subject and body
DATA: L_SUBJECT TYPE SO_OBJ_DES,
LT_BODYTEXT TYPE BCSY_TEXT,
L_BODYTEXT_ROW TYPE SOLI.
L_SUBJECT = ‚…SUBJECT…‘.
CONCATENATE …BODYTEXT…‘
INTO L_BODYTEXT_ROW.
APPEND L_BODYTEXT_ROW TO LT_BODYTEXT.

* (2) Create the email document object
DATA: DOCUMENT TYPE REF TO CL_DOCUMENT_BCS,
NUM_ROWS TYPE I,
TEXTLENGTH TYPE SO_OBJ_LEN.
DESCRIBE TABLE LT_BODYTEXT LINES NUM_ROWS.
NUM_ROWS = NUM_ROWS * 255.
MOVE NUM_ROWS TO TEXTLENGTH.
DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT(
I_TYPE = ‚RAW‘
I_TEXT = LT_BODYTEXT
I_LENGTH = TEXTLENGTH
I_SUBJECT = L_SUBJECT ).

* Add attachment
DATA: ATTDOCTYPE TYPE SOODK-OBJTP,
ATTTITLE TYPE SOOD-OBJDES,
ATTSIZE TYPE SOOD-OBJLEN,
PDFTAB TYPE SOLIX_TAB.

ATTDOCTYPE = ‚pdf‘.
ATTTITLE = ‚…TITLE…‘.
ATTSIZE = XSTRLEN( GV_FPFORMOUTPUT-PDF ).

PDFTAB = CL_DOCUMENT_BCS=>XSTRING_TO_SOLIX(
IP_XSTRING = GV_FPFORMOUTPUT-PDF ).

DOCUMENT->ADD_ATTACHMENT( EXPORTING I_ATTACHMENT_TYPE = ATTDOCTYPE
I_ATTACHMENT_SUBJECT = ATTTITLE
I_ATTACHMENT_SIZE = ATTSIZE
I_ATTACHMENT_LANGUAGE = SY-LANGU
I_ATT_CONTENT_HEX = PDFTAB ).

* Create persistent send request
DATA:SEND_REQUEST TYPE REF TO CL_BCS.
SEND_REQUEST = CL_BCS=>CREATE_PERSISTENT( ).

* Add document to send request
SEND_REQUEST->SET_DOCUMENT( DOCUMENT ).

* Get sender object
data: sender TYPE REF TO cl_sapuser_bcs.
sender = cl_sapuser_bcs=>create( ‚…SAP USERNAME…‘ ).

*      replace sender_id by distribulistion list id
sender = cl_cam_address_bcs=>create_internet_address( sender_id ).
call method send_request->set_sender
exporting
i_sender = sender.

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

* Create recipient.
data: recipient TYPE REF TO if_recipient_bcs.
recipient = cl_cam_address_bcs=>create_internet_address(
P_MAIL ).

* Add recipient with its respective attributes to send request
send_request->add_recipient( exporting i_recipient = recipient ).

* Set send immediately
send_request->set_send_immediately( ‚X‘ ).

* Send document
send_request->send( ).

COMMIT WORK.

* Create and send the email.
data: bcs_exception type ref to cx_bcs.
try.
* Enter your email code here!
catch cx_bcs into bcs_exception.
data: ex_msg type string.
ex_msg = bcs_exception->get_text( ).
write: ‚Caught exception.‘, ex_msg.
endtry.

ENDFORM.                    „send_email

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.