Application Development and Automation 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: 
Read only

Inbound email - message body missing when sent using HTML format

Former Member
0 Likes
2,775

I can process plain text inbound emails and emails with attachments. However, message content received with only HTML in the body is missing. I see the following error in transaction SOIN in the SAPConnect WorkFlow Trace. Log Action: CL_BCOM_MIME->GET_CODEPAGE_TO_CH; Log Text: Since charset is unknown, codepage 1101 (us-ascii) accepted. It appears the MIME object is parsed incorrectly.

In an EXIT I configured in SO50 the GET_BODY_PART_COUNT method shows the document as having 1 part. The attributes of the document are: DOC_TYPE = txt; BINARY = ; SUBJECT = html subject; Filename = html subject.txt; DOCSIZE = 0.

Do you have any idea how I can read the HTML based inboud email? I can see the data in transaction SOIN when I press the display MIME data button.

--Thanks

4 REPLIES 4
Read only

Former Member
0 Likes
1,721

Hi Matt,

There is a thing in SAP when you send workitems as html that it won't display anything if the WF-BATCH user is missing a printer in its user details (usually local printer)

Somehow it needs this to transform HTML to email.

Please try this and see if this works.

Kind regards, Rob Dielemans

PS there's also a workflow forum here, search that one as well as there might be answers to your question.

Read only

frankluzat
Participant
0 Likes
1,721

Hi Matt,

did you find any solution to your problem?

I'm facing the same problem since GET_BODY_PART_COUNT returns the same results as in your case but the MIME shows multipart/alternative containing one plain text part and one html part.

As suggested by rob dielemans in his post I have assigned a printer to the service user processing the inbound exit, but that didn't make any change.

Read only

0 Likes
1,721

Frank, our problem was caused by a different issue.  Our exchange folks when passing an email to SAP were truncating the message if it was over a certain size.  So, small text messages worked fine but larger messages including HTML based messages would arrive as 0 bytes.  I now have a few inbound interfaces up and running.  I spin through the parts of the document.  If content is text or HTML I use the text if the content is binary then I save the content as an attachment. 

I did not have to do anything with the printer.  You may want to check the mime settings in transaction SOIN.  Go to menu Utilities>Mime Settings.  We have "Always Save" as the setting for Incoming MIME versions of E-Mails.  You may also want to check the menu Utilities>General parameters.  I see some maximum bodypart parameters.

Here is a code snipit from 1 of my inbound interfaces...

  DATA: SENDER TYPE REF TO IF_SENDER_BCS.
  DATA: SENDER_ADDR TYPE STRING.
  DATA: LO_REPLY       TYPE REF TO CL_SEND_REQUEST_BCS .
  DATA: LI_DOCUMENT    TYPE REF TO IF_DOCUMENT_BCS,
        L_SUBJECT      TYPE SO_OBJ_DES,
        LS_TEXT        TYPE SOLI,
        LT_TEXT        TYPE SOLI_TAB,
        W_CALL_FUNCTION  TYPE CFC_FNAME,
        W_RECIPIENT    TYPE AD_SMTPADR,
        W_SENDER_ADDR TYPE AD_SMTPADR,
        W_STATUS       TYPE CO_ASTTX.


  DATA: W_BODY_COUNT TYPE INT4.
  DATA: I_BODY_CONTENT TYPE BCSS_DBPC.
  DATA: ATTRIBUTE         TYPE BCSS_DBPA,
        L_SENDER_SUBJECT  TYPE CHAR50.

  TRY.
**** init
      CLEAR E_RETCODE.

      READ TABLE IT_RECIPIENTS INTO W_RECIPIENT INDEX 1.
      TRANSLATE W_RECIPIENT TO UPPER CASE.

*      IF W_RECIPIENT CS 'ALLOWEDEMAIL.COM'.

      LO_REPLY = IO_SREQ->REPLY( ).

**** Check to make sure this is from an approved Sender
      SENDER = IO_SREQ->GET_SENDER( ).
      SENDER_ADDR SENDER->ADDRESS_STRING( ).
      TRANSLATE SENDER_ADDR TO UPPER CASE.
      W_SENDER_ADDR = SENDER_ADDR.

**** get document
      LI_DOCUMENT = IO_SREQ->GET_DOCUMENT( ).

**** get subject
      L_SENDER_SUBJECT = LI_DOCUMENT->GET_SUBJECT( ).

      CALL METHOD LI_DOCUMENT->GET_BODY_PART_COUNT
        RECEIVING
          RE_COUNT = W_BODY_COUNT.

      DO W_BODY_COUNT TIMES.

        REFRESH I_EMAIL_TEXT.

        ATTRIBUTE = LI_DOCUMENT->GET_BODY_PART_ATTRIBUTES( SY-INDEX ).

        CALL METHOD LI_DOCUMENT->GET_BODY_PART_CONTENT
          EXPORTING
            IM_PART        = SY-INDEX
            IV_PREFER_TEXT = 'X'
          RECEIVING
            RE_CONTENT     = I_BODY_CONTENT.

        IF ATTRIBUTE-BINARY = 'X' OR
           ( I_BODY_CONTENT-CONT_TEXT[] IS INITIAL AND
             NOT I_BODY_CONTENT-CONT_HEX[] IS INITIAL ).

*Handle binary content -> I have more to code if needed to save binary data as DMS attachments

   ELSE.

          IF ATTRIBUTE-DOC_TYPE = 'HTML' OR
             ATTRIBUTE-DOC_TYPE = 'html' OR
             ATTRIBUTE-DOC_TYPE = 'HTM' OR
             ATTRIBUTE-DOC_TYPE = 'htm'.

*Convert HTML to text
            CLEAR: HTML_TEXT.

            DATA: W_CONTENT_TEXT TYPE SOLI.

            LOOP AT I_BODY_CONTENT-CONT_TEXT INTO W_CONTENT_TEXT.

              CONCATENATE HTML_TEXT W_CONTENT_TEXT INTO HTML_TEXT.

            ENDLOOP.

            CALL FUNCTION 'Z_CONVERT_HTML_TO_ITF'
              EXPORTING
                HTML_TEXT = HTML_TEXT
*               W_LF      = ' '
              TABLES
                I_TEXT    = I_EMAIL_TEXT.
          ELSE.

*Convert text stream to text table
            CALL FUNCTION 'CONVERT_STREAM_TO_ITF_TEXT'
              TABLES
                TEXT_STREAM = I_BODY_CONTENT-CONT_TEXT
                ITF_TEXT    = I_EMAIL_TEXT.

          ENDIF.
          LOOP AT I_EMAIL_TEXT INTO W_EMAIL_TEXT.
            IF NOT W_EMAIL_TEXT-TDLINE IS INITIAL.
              APPEND W_EMAIL_TEXT TO I_ALL_TEXT.
            ENDIF.
          ENDLOOP.
        ENDIF.

      ENDDO.

Read only

1,721

Hi Matt,

thanks for your reply.

I had already set saving of inbound MIME to "Always".

In General Parameters I don't see anything like "Max. body parts" on my system. Unfortunately there is no search help for the parameter field. So I don't even know if additional parameters could be maintained.

Anyway, to obtain the HTML content from the multipart/alternative Email I found the following solution which works:

  DATA: lif_doc             TYPE REF TO if_document_bcs,
        lo_doc              TYPE REF TO cl_document_bcs,
        lt_obj_cont         TYPE STANDARD TABLE OF solisti1,
        lo_mail_object      TYPE REF TO cl_crm_email_data,
        ls_body             TYPE crms_email_mime_struc,
        lv_xstr             TYPE xstring,
        lv_str              TYPE string.

  TRY.

      lif_doc = io_sreq->get_document( ).

      IF lif_doc IS NOT BOUND.
        RETURN.
      ENDIF.

      io_sreq->as_mime_message(
        EXPORTING
          do_not_create = 'X'
        IMPORTING
          mime_message  = lv_xstr ).

      CALL FUNCTION 'ECATT_CONV_XSTRING_TO_STRING'
        EXPORTING
          im_xstring  = lv_xstr
          im_encoding = 'DEFAULT' "'UTF-8'
        IMPORTING
          ex_string   = lv_str.

      lo_mail_object = cl_crm_email_utility_base=>get_mail_data_from_mime(
        iv_mime_string = lv_str ).

      " HTML-Content ?
      READ TABLE lo_mail_object->body INTO ls_body WITH KEY
        is_attachment = space
        mime_type = 'text/html'.

      IF sy-subrc NE 0.
        " Plain Text?
        READ TABLE lo_mail_object->body INTO ls_body WITH KEY
          is_attachment = space
          mime_type = 'text/plain'.

        IF sy-subrc NE 0.
          READ TABLE lo_mail_object->body INTO ls_body WITH KEY
            is_attachment = space.

          IF sy-subrc NE 0.
            " No Content found?
            RETURN.
          ENDIF.
        ENDIF.
      ENDIF.

      SPLIT ls_body-content_ascii AT cl_abap_char_utilities=>cr_lf INTO TABLE lt_obj_cont.

    CATCH cx_root.

  ENDTRY.