Skip to Content
1
Former Member
Aug 25, 2016 at 10:44 AM

Send email to recipient using SAP User ID

3135 Views

Hi,

Is it possible to send an email using CL_BCS to a recipient using their SAP User ID rather than full email address? This can be useful when sending emails internal to a company. The code below can be copied-and-pasted and shows what I mean:

REPORT zemail. .

DATA: lo_document TYPE REF TO cl_document_bcs,

lo_send_request TYPE REF TO cl_bcs,

lo_sender TYPE REF TO if_sender_bcs,

lo_recipient TYPE REF TO if_recipient_bcs.

lo_send_request = cl_bcs=>create_persistent( ).

lo_document = cl_document_bcs=>create_document( i_type = 'RAW'

i_subject = 'recipient using user id' ).

lo_send_request->set_document( lo_document ).

* this works - email address is automatically determined from SAP user id:

lo_sender = cl_sapuser_bcs=>create( 'SAPUSERID' ). "user ID from SAP

lo_send_request->set_sender( i_sender = lo_sender ).

* this works - explicit email address is passed:

lo_recipient = cl_cam_address_bcs=>create_internet_address( 'first_last@company.com' ).

lo_send_request->add_recipient( i_recipient = lo_recipient ).

*** this does not work: ***

lo_recipient = cl_sapuser_bcs=>create( 'SAPUSERID' ). "user ID from SAP

lo_send_request->add_recipient( i_recipient = lo_recipient ).

*this works

lo_send_request->set_send_immediately( 'X' ).

lo_send_request->send( ).

COMMIT WORK.

WRITE:/ 'done'.

Thks,
William