Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Send email to recipient using SAP User ID

Former Member

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

12 REPLIES 12

rosenberg_eitan
Active Contributor

Hi,

See BCS_EXAMPLE_3

0 Kudos

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

rosenberg_eitan
Active Contributor

You will receive the mail here:

0 Kudos

Thanks Eitan,

Yes, with the Express flag on, but I want it to be sent to the recipient email address.

Rgds,

William

0 Kudos

You want it to get to outlook ?

0 Kudos

Yes, or whatever email client the organization uses.

0 Kudos

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)

0 Kudos

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

0 Kudos

Hi,

Not that I know of .

Regards.

0 Kudos

In SOST you see user name not address

0 Kudos

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

> 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.