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: 

Get email-addresses (SMTP) back from email sending with class cl_bcs

Former Member
0 Kudos
1,163

Hi,

I have successful send mails via class bcs (methods 'send' and 'short_message'). Now I want to get back the email-addresses where the emails where send to! I have successful get back the recipient (method bcs->recipient) and also some data from the recipients (class cl_cam_address_bcs) but not the email-address yet!

Particularly when the user maintain a new, free address in the dialog (method short_message) which are not a user, person etc. in the system yet:

How can I get the email-addresses (SMTP) of the recippients of a bcs-email?

Regards, Bernd

8 REPLIES 8

Former Member
0 Kudos
353

One method of course is to look at transaction SCOT===> Utilities===>Overview of send orders and pick it up from there.

Another would be to create a ZTABLE in your send email routine.

If your email send program is initiated by a batch job you could log the batch job.

in the BCS for sending email you've got these areas



 recipient = cl_cam_address_bcs=>create_internet_address(
                                        'your email address' ).

*     add recipient with its respective attributes to send request
      call method send_request->add_recipient
        exporting
          i_recipient  = recipient
          i_express    = 'X'.

send_request->send_request->set_link_to_outbox( 'X' ).

      call method send_request->send(
        exporting
          i_with_error_screen = 'X'
        receiving
          result              = sent_to_all ).
      if sent_to_all = 'X'.
        write text-003.
      endif.

      commit work.


I would store the recipient table somewhere.

I don't think BCS stores this as permanent data anywhere.

Note also using things like Infotype 105 might not be a good idesa since you can send an email to ANY internet address so recipients won't necessarily be SAP users on that particular system.

The ZTABLE IMO is the easiest option since you have all the data just before sending the email.

You could debug SCOT as data is also stored somewhere in the system since it can show an overview of send requests.

Cheers

jimbo

0 Kudos
353

Hi Jimbo,

I wouldn't look at an transaction.

I have coding like that:

....

....

  • --------------- Send short message with/without document ------------

CALL METHOD cl_bcs=>short_message

EXPORTING

i_subject = lv_subject_txt

  • i_text = lv_text

i_recipients = lt_bcs3_recipient

i_attachments = lt_attachment

i_starting_at_x = 12

i_starting_at_y = 5

i_ending_at_x = 97

i_ending_at_y = 32

RECEIVING

result = mo_bcs_email.

....

...

  • get subject and body text

CALL METHOD mo_bcs_email->document

RECEIVING

result = lo_bcs_document.

CALL METHOD lo_bcs_document->get_subject

RECEIVING

re_subject = ev_subject.

CALL METHOD lo_bcs_document->get_body_part_content

EXPORTING

im_part = 1

RECEIVING

re_content = ls_doc_content.

et_document[] = ls_doc_content-cont_text[].

CALL METHOD lo_bcs_document->get_body_part_attributes

EXPORTING

im_part = 1

RECEIVING

re_attributes = ls_doc_attributes.

  • recipients

CALL METHOD mo_bcs_email->recipients

RECEIVING

result = lt_bcs_recipient.

And now I will also get the actual recipients-emailaddresses, like the actual content. But with lt_bcs_recipient I get 'PERSNUMBER' and 'ADDRESSNUMBER', but not the email-adress. And that should be any internet address, your right.

So how can I get, at that moment in the sourcecode (I have the BCS-Instance), the actual recipients-email-addresses.

Regards, Bernd

0 Kudos
353

Hi there

How about something like this

Create a function Module something like this (BAPI will get email address of user)



function z_send_external_email.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(REQUESTED_STATUS) TYPE  BCS_RQST DEFAULT 'E'
*"     VALUE(DOCUMENTS) TYPE  ZEMAIL_DOCUMENTS
*"     VALUE(RECIPIENTS) TYPE  ZEMAIL_RECIPIENTS
*"  RAISING
*"      CX_BCS
*"----------------------------------------------------------------------

*
*----------------------------------------------------------------------*
* CLASS-DEFINITIONS                                                    *
*----------------------------------------------------------------------*
  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: status_mail        type         bcs_stml.
  data: first(1)           type         c.
  data: documents_line     like line of documents.
  data: recipients_line    like line of recipients.

*----------------------------------------------------------------------*
* INTERNAL TABLES                                                      *
*----------------------------------------------------------------------*
  data: l_mailtext type soli_tab.
  data: l_mailhex  type solix_tab.
  data: iaddsmtp   type bapiadsmtp occurs 0 with header line.
  data: ireturn    type bapiret2   occurs 0 with header line.

*----------------------------------------------------------------------*
* VARIABLES                                                            *
*----------------------------------------------------------------------*
  data: mail_line  like line of l_mailtext.
  data: mailx_line like line of l_mailhex.
  data: bapiadsmtp         type bapiadsmtp.

data:
lr_sender type ref to if_sender_bcs.





*----------------------------------------------------------------------*
* CONSTANTS                                                            *
*----------------------------------------------------------------------*
  constants:
    c_domain(19) type c value ' your email suffix after the @' 

  class cl_cam_address_bcs definition load.
  class cl_abap_char_utilities definition load.

  try.
*   Create persistent send request
    send_request = cl_bcs=>create_persistent( ).

    clear first.

    loop at documents into documents_line.
      if first is initial.
        move 'X' to first.
*       Build the Main Document
        if documents_line-content_hex[] is initial.
          document = cl_document_bcs=>create_document(
                              i_type    = documents_line-type
                              i_text    = documents_line-content_text
                              i_subject = documents_line-subject ).
        else.
          document = cl_document_bcs=>create_document(
                              i_type    = documents_line-type
                              i_hex     = documents_line-content_hex
                              i_subject = documents_line-subject ).
        endif.
      else.
                 if documents_line-content_hex[] is initial.
* Add Attachment
            call method document->add_attachment
              exporting
                i_attachment_type    = documents_line-type
                i_attachment_subject = documents_line-subject
                i_att_content_text   = documents_line-content_text
                i_attachment_header  = documents_line-attachment_header.
          else.
            call method document->add_attachment
              exporting
                i_attachment_type    = documents_line-type
                i_attachment_subject = documents_line-subject
                i_att_content_hex    = documents_line-content_hex
                i_attachment_header  = documents_line-attachment_header.
          endif.


      endif.
    endloop.


*   Add document to send request
    call method send_request->set_document( document ).

*   Get sender object
*    sender = cl_sapuser_bcs=>create( sy-uname ).
* use above line if you want SAP user
* use code below for ANY sender and address

*****************************************************************************************
Set SENDER EMAIL ADDR for example an XI server or your SAP machine
* you need any valid email address here 
*
**************************************************************************
call method cl_cam_address_bcs=>create_internet_address
exporting
i_address_string = 'Central_XI_Message_server-sender email'  " sender address
receiving
result = lr_sender.

*   Add sender
      call method send_request->set_sender
      exporting
       i_sender = lr_sender.

************************************************************
* Now get recipients email addres(es)
* easiest way is to use a BAPI
*
************************************************************
    loop at recipients into recipients_line.
      if recipients_line-c_address is initial.
*       Create recipient
        clear iaddsmtp.
        refresh iaddsmtp.
        clear bapiadsmtp.
        clear recipient.
*       Read the E-Mail address for the user
        call function 'BAPI_USER_GET_DETAIL'
          exporting
            username = recipients_line-uname
          tables
            return   = ireturn
            addsmtp  = iaddsmtp.
        loop at iaddsmtp where std_no = 'X'.
          clear bapiadsmtp.
          move iaddsmtp to bapiadsmtp.
        endloop.

* If no email got from BAPI create manually
*
*       If no E-mail address was found, create one.
        if bapiadsmtp-e_mail = ''.
          concatenate recipients_line-uname c_domain
                    into recipients_line-c_address.
        else.
          move bapiadsmtp-e_mail to recipients_line-c_address.
        endif.
      endif.

      recipient = cl_cam_address_bcs=>create_internet_address(
recipients_line-c_address ).
*     Add recipient with its respective attributes to send request
      call method send_request->add_recipient
        exporting
          i_recipient  = recipient
          i_express    = recipients_line-i_express
          i_copy       = recipients_line-i_copy
          i_blind_copy = recipients_line-i_blind_copy
          i_no_forward = recipients_line-i_no_forward.

    endloop.

* After this loop your recipient table should have all the recipients actual email addresses in them 
* together with the User Id's
*
  status_mail = 'A'.
*   Set that you don't need a Return Status E-mail
    status_mail = requested_status.
    call method send_request->set_status_attributes
      exporting
        i_requested_status = requested_status
        i_status_mail      = status_mail.
*   Set send immediately flag
    send_request->set_send_immediately( 'X' ).

*   Send document
    call method send_request->send( ).

    commit work.

    catch cx_bcs into bcs_exception.
      raise exception bcs_exception.

  endtry.
endfunction.

structure of parameters for the function module



* data structures for Z_EMAIL_SEND_EXTERNAL

REQUESTED_STATUS   TYPE BCS_RQST   (value  'E')
DOCUMENTS      TYPE   ZEMAIL_DOCUMENTS
RECIPIENTS     TYPE   ZEMAIL_RECIPIENTS 


ZEMAIL_DOCUMENTS   LINE type of ZEMAIL_DOCUMENTS_ROW
components

TYPE   TYPE  SO_OBJ_TYP   CHAR 3
SUBJECT TYPE SO_OBJ_DES   CHAR 50
CONTENT_TEXT TYPE  SOLI_TAB
CONTENT_HEX  TYPE SOLIX_TAB
ATTACHMENT_HEADER TYPE SOLI_TAB

RECIPIENTS TYPE ZEMAIL_RECIPIENTS

ZEMAIL_RECIPIENTS LINE TYPE Z_EMAIL_RECIPIENTS_ROW

components

UNAME TYPE sy-uname
C_ADDRESS TYPE AD_SMTPADR  (Char 241)
I_EXPRESS TYPE OS_BOOLEAN
I_COPY   TYPE OS_BOOLEAN
I_BLIND_COPY TYPE OS_BOOLEAN

In the table recipients the email address is stored in the field c_address.

I'm now a bit confused as to what you actually want since I assume you are actually creating the email addresses yourself from either master data or manually.

Cheers

jimbo

0 Kudos
353

Hi,

Many thanks for your examples, but that doesn't solve my problem.

What I want is is the actual recipients-addresses from a sended email in bcs: In my application I have the scenarios that I call the BCS with Dialog (bcs->edit or bcs=>short_message).

In this dialog the user can added any recipients he want.

So I will get the recipients-email-address (for protocolling) close after the methods bcs->edit or bcs=>short_message, like I did get the actual sent content.

Regards, Bernd

0 Kudos
353

Hi,

try calling method GET_TECHNICAL_RECIPIENTS from the SEND_REQUEST attribute of the returning parameter.

It should return a table containing the informations you need.

Hope this helps,

R.

0 Kudos
353

Hi,

thanks for your aid.

I tried:

"CALL METHOD mo_bcs_email->GET_TECHNICAL_RECIPIENTS"

where mo_bcs_email is an instance of CL_BCS. It doesn't work: The method GET_TECHNICAL_RECIPIENTS are not known at CL_BCS. Also I didn't find the method in CL_BCS. From where is it? Or is it protected?

Please specify this method.

Regards Bernd

0 Kudos
353

Hi,

now I find the TECHNICAL_RECIPIENTS: But they are empty: I had a look with the debugger after I fill an recipient address in the dialog.

My code looks:

....

CALL METHOD cl_bcs=>short_message

EXPORTING

i_subject = l_subject_txt

i_text = text

i_recipients = recips

i_attachments = attachments

i_starting_at_x = 12

i_starting_at_y = 5

i_ending_at_x = 97

i_ending_at_y = 22

RECEIVING

result = send_request.

data: RESULT TYPE BCSY_RETE.

data: send_request2 TYPE REF TO CL_SEND_REQUEST_BCS.

send_request2 = send_request->send_request.

RESULT = send_request2->GET_TECHNICAL_RECIPIENTS( ).

....

Regards, Bernd

0 Kudos
353

Hi there

You can try using method recipients in class cl_bcs.

This should return a link to the receiver instances. You might have to do another call or two to decompose this result further.

Not sure also how "persistent' the recipient list is.

cheers

jimbo