Skip to Content
author's profile photo Former Member
Former Member

how to send smart form to the email as a body and not in attachments

hi Guys

how to send smart form to the email as a body and not in attachments?

Thanks in advance

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Nov 22, 2007 at 05:47 AM

    HI

    /people/pavan.bayyapu/blog/2005/08/30/sending-html-email-from-sap-crmerp

    form process_webform
    .
    .
    .
    * activate XSF Output Mode
      ls_output_options-xsf        = c_charx.        " XSF Output active
      ls_output_options-xsfcmode   = c_charx.        " Get XSF params from program
      ls_output_options-xsfoutmode = c_application.  " Application
      ls_output_options-xsfformat  = c_charx.       " Formatting ON
      clear ls_output_options-xsfoutdev.
     
      ls_xsfparam_line-name  = 'GRAPHICS'.
      ls_xsfparam_line-value = 'EXTRACT'.
      append ls_xsfparam_line to ls_output_options-xsfpars.
     
      ls_xsfparam_line-name  = 'GRAPHICS-DIRECTORY'.            "#EC NOTEXT
      ls_xsfparam_line-value = c_gr_dir.
      append ls_xsfparam_line to ls_output_options-xsfpars.
     
      ls_xsfparam_line-name  = 'CONTENT-ID'.                    "#EC NOTEXT
      ls_xsfparam_line-value = 'ENABLE'.                        "#EC NOTEXT
      append ls_xsfparam_line to ls_output_options-xsfpars.
     
    * silent mode ON
      ls_output_options-tdimmed = space.
      ls_output_options-tdnewid = space.
      ls_control_parameters-no_dialog = c_charx.
     
      call function 'SSF_FUNCTION_MODULE_NAME'
        exporting
          formname           = pi_form
        importing
          fm_name            = l_fm_name
        exceptions
          no_form            = 1
          no_function_module = 2
          others             = 3.
     
      if sy-subrc <> 0.
    *   error handling
        message id sy-msgid type sy-msgty number sy-msgno
                with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        exit.
      endif.
     
      call function l_fm_name
        exporting
          control_parameters = ls_control_parameters
          output_options     = ls_output_options
          user_settings      = space
        importing
          job_output_info    = ls_output_data
        exceptions
          formatting_error   = 1
          internal_error     = 2
          send_error         = 3
          user_canceled      = 4
          others             = 5.
     
      if sy-subrc <> 0.
    *   error handling
        message id sy-msgid type sy-msgty number sy-msgno
                with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      endif.
     
      po_html       = ls_output_data-xmloutput-trfresult.
      po_t_graphics = ls_output_data-xmloutput-xsfgr.
     
    endform.                    "process_webform
     
    ***************************
    form send_webform
    .
    .
    .
    .
      clear l_html_xstr.
      loop at pi_s_html-content into l_html_raw.
        concatenate l_html_xstr l_html_raw into l_html_xstr in byte mode.
      endloop.
     
      l_html_xstr = l_html_xstr(gs_html_data-length).
     
      call function 'SCP_TRANSLATE_CHARS'
        exporting
          inbuff       = l_html_xstr
          incode       = '4110'                                 " utf-8
          csubst       = c_charx
          substc_space = c_charx
        importing
          outbuff      = l_html_str
          outused      = l_html_len
        exceptions
          others       = 1.
     
      if sy-subrc ne 0.
        "do nothing
      endif.
     
    * change encoding utf-8 to latin1
      replace all occurrences of 'utf-8' in l_html_str with 'latin1' ignoring case.
     
      replace all occurrences of 'absolute' in l_html_str with 'relative' ignoring case.
     
      replace all occurrences of 'overflow : auto'
                  in l_html_str with 'overflow : hidden' ignoring case.
     
    * The following code will replace the standard text shown in an html link
    * such as (www.sap.com) with the text passed along with the link (contained in
    * brackets [ ] ).  An example would be: "www.sap.com[Click me]" will then be
    * displayed as a link on the email with "... Click me ..." as the text.  HTML links
    * without brackets will be displayed normally (ie. www.sap.com)+
      do.
    *   Get the length for the entire HTML code for the URL and Name
        find '<a href="' in section offset l_aref_end of l_html_str match offset l_aref_start.
     
        if sy-subrc ne 0.
          exit.
        endif.
     
        find '</a>' in section offset l_aref_start of l_html_str match offset l_aref_end.
        l_aref_length = ( l_aref_end + 4 ) - l_aref_start.
     
    *   Find the URL/name
        l_lnk_start = l_aref_start + 9.
        find '">' in section offset l_aref_start of l_html_str match offset l_lnk_end.
        l_lnk_length = l_lnk_end - l_lnk_start.
    *   Save the URL/name
        l_link_all = l_html_str+l_lnk_start(l_lnk_length).
     
    *   Find where the name starts and ends
        find '[' in l_link_all match offset l_name_start.
        if sy-subrc ne 0.
          continue.
        endif.
        find ']' in l_link_all match offset l_name_end.
        if sy-subrc ne 0.
          continue.
        endif.
     
    *   Seperate out the URL
        l_link_url = l_link_all+0(l_name_start).
     
    *   Seperate out the name
        l_name_start = l_name_start + 1.
        l_name_length = l_name_end - l_name_start.
        l_link_name = l_link_all+l_name_start(l_name_length).
     
    *   Replace the first URL/Name occurence with just the URL
        replace first occurrence of l_link_all
                in section offset l_aref_start length l_aref_length
                of l_html_str with l_link_url.
    *   Replace the second URL/Name occurence with just the Name - first
    *   substitute special characters.
        replace all occurrences of '&' in l_link_all with '&'.
        replace all occurrences of '>' in l_link_all with '>'.
        replace all occurrences of '<' in l_link_all with '<'.
        replace first occurrence of l_link_all
                in section offset l_aref_start length l_aref_length
                of l_html_str with l_link_name.
     
    *   Reset ending point
        l_aref_end = l_aref_end - ( l_lnk_length + 2 ).
      enddo.
     
      l_html_len = strlen( l_html_str ).
     
      l_offset = 0.
      l_length = 255.
     
      while l_offset < l_html_len.
        l_diff = l_html_len - l_offset.
        if l_diff > l_length.
          ls_soli-line = l_html_str+l_offset(l_length).
        else.
          ls_soli-line = l_html_str+l_offset(l_diff).
        endif.
        append ls_soli to lt_soli.
        add l_length to l_offset.
      endwhile.
     
      create object lo_mime_helper.
     
      call method lo_mime_helper->set_main_html
        exporting
          content = lt_soli.
     
      loop at pi_t_graphics into gs_graphic.
        clear l_gr_xstr.
        loop at gs_graphic-content into l_gr_raw.
          concatenate l_gr_xstr l_gr_raw-line into l_gr_xstr in byte mode.
        endloop.
        l_gr_xstr = l_gr_xstr(gs_graphic-length).
        l_offset = 0.
        l_length = 255.
        clear lt_solix[].
        while l_offset < gs_graphic-length.
          l_diff = gs_graphic-length - l_offset.
          if l_diff > l_length.
            ls_solix-line = l_gr_xstr+l_offset(l_length).
          else.
            ls_solix-line = l_gr_xstr+l_offset(l_diff).
          endif.
          append ls_solix to lt_solix.
          add l_length to l_offset.
        endwhile.
     
        concatenate c_gr_dir gs_graphic-graphics '.bmp' into l_filename.
        concatenate c_gr_dir gs_graphic-graphics '.bmp' into l_content_id.
        l_content_type = gs_graphic-httptype.
        l_obj_len      = gs_graphic-length.
        call method lo_mime_helper->add_binary_part
          exporting
            content      = lt_solix
            filename     = l_filename
            extension    = 'BMP'
            content_type = l_content_type
            length       = l_obj_len
            content_id   = l_content_id.
      endloop.
     
      try.
          l_standard_txt = pi_smartform.
          call function 'READ_TEXT'
            exporting
              id       = 'ST'
              language = sy-langu
              name     = l_standard_txt
              object   = 'TEXT'
            tables
              lines    = lt_lines.
     
          read table lt_lines into ls_lines index 1.
          replace '&1' in ls_lines-tdline with pi_belnr.
          replace '&2' in ls_lines-tdline with pi_bukrs.
     
            move ls_lines-tdline to l_subject.
     
         lo_doc_bcs = cl_document_bcs=>create_from_multirelated(
                                        i_subject          = l_subject
                                        i_multirel_service = lo_mime_helper ).
    * Add Attachment
    *      types: begin of email_docs,
    *                   type    type so_obj_tp,
    *                   subject type so_obj_des,
    *                   content_text type soli_tab,
    *                   content_hex  type solix_tab,
    *             end of email_docs.
    *      types: email_docs_t type standard table of email_docs.
    *
    *      data: documents type        email_docs_t,
    *      documents_line like line of documents.
    *
    *      data: soli_tab type soli_tab,
    *            soli type soli.
    *      soli = 'This is line one'.
    *      append soli to soli_tab.
    *      soli = 'And this is line two'.
    *      append soli to soli_tab.
    *
    *      documents_line-type = 'RAW'.
    *      documents_line-subject = 'Subject'.
    *      documents_line-content_text = soli_tab.
    *      append documents_line to documents.
    *      call method lo_doc_bcs->add_attachment
    *        EXPORTING
    *          i_attachment_type    = documents_line-type
    *          i_attachment_subject = documents_line-subject
    *          i_att_content_text   = documents_line-content_text.
    *
        catch cx_document_bcs.
    *   error handling
          exit.
        catch cx_bcom_mime.
    *   error handling
          exit.
        catch cx_gbt_mime.
    *   error handling
          exit.
      endtry.
     
    * create send_request
      try.
          lo_bcs = cl_bcs=>create_persistent( ).
        catch cx_send_req_bcs.
    *   error handling
          exit.
      endtry.
      try.
          lo_bcs->set_document( i_document = lo_doc_bcs ).
        catch cx_send_req_bcs.
    *   error handling
          exit.
      endtry.
     
    * create recipient
      if pi_recipient ns '@'.
        l_username = pi_recipient.
        translate l_username to upper case.                     "#EC *
        try.
            lo_recipient = cl_sapuser_bcs=>create( l_username ).
          catch cx_address_bcs.
    *     error handling
            exit.
        endtry.
      else.
        l_mail_address = pi_recipient.
        try.
            lo_recipient = cl_cam_address_bcs=>create_internet_address( i_address_string = l_mail_address ).
     
          catch cx_address_bcs.
    *     error handling
            exit.
        endtry.
      endif.
     
      try.
          lo_bcs->add_recipient( i_recipient = lo_recipient ).
        catch cx_send_req_bcs.
    *   error handling
          exit.
      endtry.
     
    * send
      try.
    *     RECEIPTS ONLY FOR ERRORS
          call method lo_bcs->send_request->set_requested_status
            exporting
              i_requested_status = 'N'.                         "#EC NOTEXT
     
          lo_bcs->send( ).
          commit work.
        catch cx_send_req_bcs.
    *   error handling
          exit.
      endtry.
     
    endform.                    "send_webform

    ]

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 22, 2007 at 05:39 AM

    Hi Kittu,

    Try this link:

    Need help in sending sapscript/smartform as body of email, No attachment

    Reward points if helpful.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.