08-25-2016 11:44 AM
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
08-25-2016 12:07 PM
08-25-2016 12:12 PM
Thanks Eitan.
I reviewed all the BCS example programs, but the cl_sapuser_bcs=>create line for recipients doesn't work (for me).
Could you execute BCS_EXAMPLE_3 on your system please (not setting the 'Express' flag), and see if you get an email please?
Thks,
William
08-25-2016 12:13 PM
08-25-2016 12:15 PM
Thanks Eitan,
Yes, with the Express flag on, but I want it to be sent to the recipient email address.
Rgds,
William
08-25-2016 12:20 PM
08-25-2016 12:23 PM
08-25-2016 12:27 PM
I use
DATA: st_address TYPE bapiaddr3 .
CALL FUNCTION 'BAPI_USER_GET_DETAIL'
EXPORTING
username = 'SAPUSERID'
IMPORTING
address = st_address
TABLES
return = it_return.
and then "explicit email address is passed" (st_address-e_mail)
08-25-2016 12:31 PM
Thanks Eitan,
Yes, that's what I'm doing too 🙂 And passing the email address into cl_cam_address_bcs=>create_internet_address
However my question was whether the email address for Recipients can be determined automatically from their SAP user id, in the same way it is done for Senders.
Thks,
William
08-25-2016 12:43 PM
08-25-2016 12:47 PM
08-25-2016 12:54 PM
Thanks Eitan.
I thought it was just me 🙂
I don't know why SAP coded if_recipient_bcs differently to if_sender_bcs in this regard but such is life.
if_sender_bcs <- user id or email address
if_recipient_bcs <- email address only (user id + express flag goes to SAP inbox. user id only => no effect)
Thks,
William
01-21-2021 11:11 AM
> However my question was whether the email address for Recipients can be determined automatically from their SAP user id, in the same way it is done for Senders
Yes, it can be. Use cl_cam_address_bcs=>create_user_home_address method.