cancel
Showing results for 
Search instead for 
Did you mean: 

Send an smartform as body of a mail

Former Member
0 Kudos

Hello,

I would like know if there is another way of doing this: "Send an smartform as body of a mail". Now it is sending attached as pdf but the user prefers to view the smartform on the body of the message.

This is a CS formulary and I think that (perhaps) at the options of "output_options TYPE ssfcompop," should be another of this.

Thanks

Accepted Solutions (0)

Answers (6)

Answers (6)

Former Member
0 Kudos

Hello,

Thanks by your helpfuls answer. This thing is very pretty solution but I cannot control that the users mail configuration.

I had think another thing, is it posible to change the formulary to a image, (bmp, jpg ...) and put this in the body?

aidan_mulcahy
Active Participant
0 Kudos

do you mean convert the html page to one image and 'paste' it into the body of the mail? If so, I don't know what to do for that.

Check out this thread:

may help??

Former Member
0 Kudos

Hello Kroc,

I try the code of the link

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

And it runs nice at Outlook, but in web mail and another Mail clients the formulary lost the format (box, character type, etc).

I saw that in the smartform there is an option "Output XFS + HTML". Know my question is ¿Can I send the smartform only changing this option? Because executing the report apparently it sends the formulaty but I enter in the sost transaction and it don't appears.

aidan_mulcahy
Active Participant
0 Kudos

Pepe,

I tried XFS + HTML here now and the output is the same.

May be a silly question but do you have html output turned on in you other mail clients that you are testing?

Former Member
0 Kudos

I had change the smartform to XSF output and output mode Application. And my output options are the same that you say. But the result is the same.

The rare caracters is solved changing 'iso-8859-1' to 'UTF-8' .

aidan_mulcahy
Active Participant
0 Kudos

I have included our code to process/send our smartform via email. you should be able to see the solution in there.....


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. <a href="www.sap.com)+" TARGET="test_blank">www.sap.com)+</a>
  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

Former Member
0 Kudos

Hi Kroc,

Thanks for your answers, I try the forms from the link that you says and it works me but or less. The smartforms appears attached like html file and a bmp file of the smartform that it uses like logo, its appears attached too.

On the other hand, the text of the html file that it has the smartform, it has rare symbols like Â

aidan_mulcahy
Active Participant
0 Kudos

i'd say look at your output options in both the general attributes and in the code.

my output options are:

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.

as for the funny characters, one of the sample reports should have code for changing & to &amp etc... if the character is not one of them, i dunno what it could be. The output options solved a lot of my issues.

aidan_mulcahy
Active Participant
0 Kudos

forgot to add this....

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

is a good intro too. It's for CRM but explains it well

aidan_mulcahy
Active Participant
0 Kudos

create the smartform as XSF output and output mode Application.

we wrote our own code for it, but it was based on the report SF_XSF_DEMO_MAIL. Copy that - it's pretty straight-forward from there.