Skip to Content

We can trigger e-mails with the multiple attachments from XI either using SAP Connect or Mail adapter. You can configure SAP connect using the note

455140

.
We have chosen SAP connect for its simplicity and ease of use. RFC adapter is created to send e-mails using SAP Connect.But there are problems when sending attachments with unknown extensions.I will discuss the problem and provide the configuration that has to be done for overcoming it.

I am working on a scenario where I need to send the content of the Idoc as e-mail with 2 attachments. Excellent articles were posted by

Thomas Jung

to trigger e-mails with attachments using CL_DOCUMENT_BCS API. But this code works fine when we are triggering e-mails with attachments having known formats or the formats present in TSOTD table.

In my current project I need to trigger e-mails having attachments with extensions .QRN and. QTX. I modified my code accordingly for generating the required extension. Surprisingly after viewing the attached file I can clearly find out that there is a data loss and attachments files are not proper.

I have raised the problem it in ABAP forum .I did not get any solution rather some one asked me if I solute it. We raised OSS with SAP for the same and after couple of transactions with SAP; it has come up with a solution, which re-solved my problem.

I provided the sample RFC code here for triggering e-mails with multiple attachments which can be useful for non SAP XI developers to just plug in the code and also provide the details what has to be done for generating files with extensions that are not provided in the TSOTD table.

FUNCTION ZXI_SEND_MAIL_MULTI_ATT.

*”—-


“Local Interface:

*”  IMPORTING

*”     VALUE(SUBJECT) TYPE  SO_OBJ_DES OPTIONAL

*”     VALUE(ATTACH_NAME1) LIKE  SOOD-OBJDES OPTIONAL

*”     VALUE(ATTACH_NAME2) LIKE  SOOD-OBJDES OPTIONAL

*”     VALUE(EXT1) LIKE  SOODK-OBJTP OPTIONAL

*”     VALUE(EXT2) LIKE  SOODK-OBJTP OPTIONAL

*”  TABLES

*”      IT_CONTENT TYPE  SOLI_TAB OPTIONAL

*”      IT_ATTACH TYPE  SOLI_TAB OPTIONAL

*”      IT_ATTACH1 TYPE  SOLI_TAB OPTIONAL

*”—-


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

  DATA i_attachment_size TYPE SOOD-OBJLEN.

  DATA IT_RECV LIKE ZMAILMAP OCCURS 0 WITH HEADER LINE.

  • Creates persistent send request

  send_request = cl_bcs=>create_persistent( ).

  TRY.

*****Create txt mail document**************************

      document = cl_document_bcs=>create_document(

                                    i_type    = ‘RAW’

                                    i_text = it_content[]

                                    i_subject = subject ).

**********************************************************

**************Creates Attachment 1***********************

      CALL METHOD DOCUMENT->ADD_ATTACHMENT

        EXPORTING

          I_ATTACHMENT_TYPE    = EXT1

          I_ATTACHMENT_SUBJECT = ATTACH_NAME1

          I_ATT_CONTENT_TEXT   = IT_ATTACH[].

************Creates Attachment 2*************************

      CALL METHOD DOCUMENT->ADD_ATTACHMENT

        EXPORTING

          I_ATTACHMENT_TYPE    = EXT2

          I_ATTACHMENT_SUBJECT = ATTACH_NAME2

          I_ATT_CONTENT_TEXT   = IT_ATTACH1[].

  • Add document to send request

      CALL METHOD send_request->set_document( document ).

  • Get sender object

      sender = cl_sapuser_bcs=>create( sy-uname ).

  • Add sender

      CALL METHOD send_request->set_sender

        EXPORTING

          i_sender = sender.

*List of recipient  mail addresses

************************************************

      clear it_recv.

      it_recv-mailid = <your-email id>.

      append it_recv.

*************************************************

      loop at it_recv.

***********e-mail list************************

        translate it_recv-mailid to lower case.

        recipient = cl_cam_address_bcs=>create_internet_address(

       it_recv-mailid ).

        CALL METHOD send_request->add_recipient

          EXPORTING

            i_recipient  = recipient

            i_express    = ‘U’

            i_copy       = ‘ ‘

            i_blind_copy = ‘ ‘

            i_no_forward = ‘ ‘.

      endloop.

**********Trigger e-mails immediately****************************

      send_request->set_send_immediately( ‘X’ ).

      CALL METHOD send_request->send( ).

      COMMIT WORK.

    CATCH CX_DOCUMENT_BCS INTO bcs_exception.

  ENDTRY.

ENDFUNCTION.

I map the contents from Idoc to the RFC interface IT_CONTENT and attachment data to IT_ATTACH1, IT_ATTACH2 respectively from the IR.

We need to maintain the extensions in the table TSOPE using transaction SOPE to prevent the data loss with the extensions .QRN and .QTX. Flagging them as ASCII in SOPE will allow the files to be treated as just ASCII files and hence prevent from data loss.

SOPE

With this configuration the attachments are sent properly without any data loss.

To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

    1. Sravya Talanki Post author
      you declare zmailmap structure having one field mail id or can use any existing structure which has that field or like any so structure.
      (0) 

Leave a Reply