Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Attachment in mail not opening

Dear Guys,

We need to send a mail to external mail ID with word doc as attachment. so we are using the function module SO_NEW_DOCUMENT_ATT_SEND_API1 .

I am getting the mail with attachment. But when i click on the attachment an error pops up telling the file content is corrupted.The following is the code used

DATA : it_packing_list TYPE TABLE OF sopcklsti1,
         gd_doc_data TYPE sodocchgi1,
         wa_packing_list LIKE LINE OF  it_packing_list,
         psubject(90) TYPE c,
         it_message TYPE STANDARD TABLE OF solisti1,
         wa_it_message LIKE LINE OF it_message,
         c1(99) TYPE c,
         c2(15) TYPE c,
         lv_studentmailid type PA0105-USRID_LONG,
         num_lines TYPE i,
         it_receivers TYPE TABLE OF somlreci1,
         wa_it_receivers LIKE LINE OF  it_receivers,
        it_contents_bin type table of SOLISTI1,"SOLIX,
        wa_contents_bin  like line of it_contents_bin ,
          it_BINARY_TAB    type table of sdokcntbin,
         wa_BINARY_TAB like line of it_BINARY_TAB.

*Set receiver's address
  FREE wa_it_receivers.
  wa_it_receivers-receiver = lv_studentmailid.
  wa_it_receivers-rec_type = 'U'.
  APPEND wa_it_receivers TO it_receivers.


  DESCRIBE TABLE it_receivers LINES num_lines.
  IF  num_lines IS NOT INITIAL.

*Set Subject of Mail
    psubject ='Booked'.

*Set Content of mail
    CLEAR wa_it_message.
    c1 = 'Dear'.
    c2 =  lv_name."STUDENTNAME .
    CONCATENATE c1 c2 ',' INTO
    wa_it_message-line   SEPARATED BY space.
    APPEND wa_it_message TO it_message.

    CLEAR wa_it_message.
    c1 = 'Susscess.'.
    wa_it_message-line = c1.
    APPEND wa_it_message TO it_message.

 
*&  SEND_EMAIL_MESSAGE
    gd_doc_data-doc_size = 1.
*Populate the subject/generic message attributes
    gd_doc_data-obj_langu = sy-langu.
    gd_doc_data-obj_name = 'SAPRPT'.
    gd_doc_data-obj_descr = psubject.
    gd_doc_data-sensitivty = 'F'.

*Describe the body of the message
    CLEAR wa_packing_list.
    REFRESH it_packing_list.
    wa_packing_list-transf_bin = space.
    wa_packing_list-head_start = 1.
    wa_packing_list-head_num = 0.
    wa_packing_list-body_start = 1.

    DESCRIBE TABLE it_message LINES wa_packing_list-body_num.
    wa_packing_list-doc_type = 'INT'."RAW'.
    APPEND wa_packing_list TO it_packing_list.

data : wa_file type Z_ATTA,
      lv_xstring type xstring,
      wa_CONTENTS_HEX type SOLIX,
      it_CONTENTS_HEX type standard table of SOLIX.
CALL FUNCTION 'Z_GET_ATTACHMENTS'
  EXPORTING
    DOUBTNO          = '00000011'
    LINEITEMNO       = '2'
 IMPORTING
   FILE             = wa_file.


*Attachment packing list
      wa_packing_list-TRANSF_BIN = 'X'.
      wa_packing_list-HEAD_START = 1.
      wa_packing_list-HEAD_NUM = 1.
      wa_packing_list-BODY_START = 1.
      wa_packing_list-BODY_NUM = 1.
      wa_packing_list-doc_type = 'doc'.
      wa_packing_list-obj_name = 'ATTACHMENT'.
      wa_packing_list-OBJ_DESCR =  'desc'.

      APPEND wa_packing_list to it_packing_list.

       

CALL FUNCTION 'HR_KR_STRING_TO_XSTRING'
        EXPORTING
          UNICODE_STRING         = wa_file-filecontent"string format
       IMPORTING
         XSTRING_STREAM         = lv_xstring.


*Attachment
clear it_binary_tab.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
        EXPORTING
          BUFFER                =  lv_xstring
       TABLES
          BINARY_TAB            = it_binary_tab.



    loop at it_BINARY_TAB into wa_BINARY_TAB.
      wa_contents_bin-line = wa_BINARY_TAB-line.
      append wa_contents_bin to it_contents_bin.
    endloop.

loop at it_binary_tab into wa_binary_tab.
   wa_CONTENTS_HEX-line = wa_binary_tab-lINE.
 append  wa_CONTENTS_HEX to it_CONTENTS_HEX.
endloop.

* Call the FM to post the message to SAPMAIL
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
      EXPORTING
        document_data              = gd_doc_data
        put_in_outbox              = 'X'
        commit_work                = 'X'
      TABLES
        packing_list               = it_packing_list
        contents_txt               = it_message
*        contents_bin            = it_contents_bin
         CONTENTS_HEX   = it_CONTENTS_HEX
        receivers                   = it_receivers
      EXCEPTIONS
        too_many_receivers         = 1
        document_not_sent          = 2
        document_type_not_exist    = 3
        operation_no_authorization = 4
        parameter_error            = 5
        x_error                    = 6
        enqueue_error              = 7
        OTHERS                     = 8.

The attachmen is currupted...please correct me where i am going wrong...

Regards,

Shamila

Tags:
Former Member
Not what you were looking for? View more on this topic or Ask a question