Skip to Content
Author's profile photo praveen kumar mannala


Yeah there are already documents available on this topic. Only reason why i am posting this document is the difference in the code. There are some classes availabe, which will be very useful in the process of sending smart forms in the HTML format.

this report program will give you an idea on how to convert smart form into html format and send it as an email along with the images(if smart form consists any ).

There is no need of manipulating much on images content. All we need to do is just covert the image into binary content. There is a class in SAP CRM 

cl_crm_email_data , which has one method  send_email, which will help us to make this process quite easy. We can easily embed the images in to the email content. Observe this class closely, may be you can get more ideas.

Eventhough , i used appropriate comments in the program. It would be better if i tell you some importants points here only. There is some piece of code in the report program regarding image maniplation. the basic logic is , if there is one image in the smart form, then there will be one img tag in the converted html output. This img tag will have one attribute called ‘src’.  The one possible value for this attribute will be like this”cid:xxxxxx” .here ‘xxxxxx’ is image name. 

This image name and the value for content id, which we will send to one internal table(see the report program) , should be same. This will help the email client to find out the embedded image in the email.

i have written this program assuming that smart form will have only one can modify it according to your requirements.  i hope users already have some basic knowledge on XSF format. please refere to below link if you want to know more about XSF fomrat and parameters we need to send to convert smart form into HTML format.

For the people, who want to investigate furhther on this topic. There is one report program available in SE38 transaction.

SF_XSF_DEMO_MAIL. kindly check it.

I hope it helps you.

Any suggestions are welcome.

   REPORT  zsmartform_send_mail.

TYPES: BEGIN OF ty_cmail_html_parser,
        part                TYPE string,
        tag                 TYPE string,
        attributes          TYPE tihttpnvp,
        is_end_tag          TYPE xfeld,
        ref_tag_index       TYPE i,
       END  OF ty_cmail_html_parser.

TYPES: lt_mail_html_parset TYPE STANDARD TABLE OF ty_cmail_html_parser.

***************************LOCAL INTERNAL TABLES*****************************************************
          lt_html_raw        TYPE            tsfixml,             “XML output information.
          lt_archive         TYPE            tsfdara,             “SAP Smart Forms: Table With Archive Indexes
          lt_graphics        TYPE            tsf_xsf_gr,          “Image information
          lt_part            TYPE            lt_mail_html_parset, “parsed html information.
          lt_imgsrc          TYPE TABLE OF   string,              “image source information.
          lt_result          TYPE            match_result_tab,    “find stament result
          lt_imageid         TYPE TABLE OF   string,             “image ids
          lt_mail_body       TYPE  crmt_email_mime_struc,
          lt_to             TYPE              crmt_email_recipients,            “to email addresses
          lt_cc             TYPE              crmt_email_recipients.            “CC email addresses.

*****************local structure***********************************

DATA: ls_output_options        TYPE  ssfcompop,        “output options.
      ls_xsfparam_line         TYPE  ssfxsfp,          “parametes to get html format.
      ls_job_output_info       TYPE  ssfcrescl,        “Joboutput information.
      ls_xmloutput             TYPE  ssfxmlout,        “output information in XML format.
      ls_control_parameters    TYPE  ssfctrlop,        “control parameters.
      ls_part                  TYPE REF TO    ty_cmail_html_parser,“partsed html information
      ls_graphic               TYPE           ssf_xsf_gr,       “image information
      ls_gr_raw                TYPE           bapiconten,       “business service document file content
      ls_attribute             TYPE REF TO    ihttpnvp,         “html tag attribute information.
      ls_imgsrc                LIKE LINE OF   lt_imgsrc,        “image source information.
      ls_imageinfo             TYPE LINE OF   crmt_email_image,  “image information.
      ls_result                LIKE LINE OF   lt_result,         “find result.
      ls_mail_body             LIKE LINE OF   lt_mail_body,                  “message id.
      ls_recep                 LIKE LINE OF      lt_to.                         “TO email addresses

****************local variables****************************************

DATA: lv_function_name     TYPE           rs38l_fnam,           “Name of function module of smart form.
      lv_xstring           TYPE           xstring,              “Xstring data.
      lv_html_xstring      TYPE           xstring,              “Xstring data.
      lo_conv              TYPE REF TO    cl_abap_conv_in_ce,   “conversion class.
      lv_html_temp         TYPE           string,               “html data.
      lv_len               TYPE           i,                    “Length of the string.
      lv_img_src           TYPE           string,               “image source value.
      lo_create_mail       TYPE REF TO    cl_crm_email_data,              “mail data object
      lv_activity          TYPE                  sysuuid_x,                      “activity guid
      lv_imagename         TYPE           string.


DATA :       lc_flag       TYPE  c        VALUE ‘X’,                                 “flag constant
             lc_outmode    TYPE  c        VALUE ‘A’,                                 “Application mode
             lc_graphics   TYPE string    VALUE ‘GRAPHICS’,                          “parameter
             lc_extract    TYPE string    VALUE ‘EXTRACT’,                           “Parameter
             lc_contentid  TYPE string    VALUE ‘CONTENT-ID’,                        “content id
             lc_enable     TYPE string    VALUE ‘ENABLE’,                            “enable
             lc_img        TYPE string    VALUE ‘img’,                               “image tag
             lc_src        TYPE string    VALUE ‘src’,                               “src property of image tag.
             lc_text_html       TYPE string  VALUE ‘text/html’,                      “body content type.
             lc_body_html       TYPE string           VALUE ‘body.htm’.        “body html .

PARAMETERS : lv_form   TYPE   tdsfname,                             “smart form name.
             lv_mail   TYPE   string.                               “email address

“getting the smartform function module.

CLEAR lv_function_name.

    formname           = lv_form
    fm_name            = lv_function_name
    no_form            = 1
    no_function_module = 2
    OTHERS             = 3.

IF sy-subrc IS INITIAL.

  “filling the necesary parameters to get the smartform data

  “(XML output for Smart Form) FORMAT.
  CLEAR ls_output_options.

  ls_output_options-xsf        = lc_flag.      ” XSF Output active
  ls_output_options-xsfcmode   = lc_flag.      ” Get XSF params from program
  ls_output_options-xsfoutmode = lc_outmode.   ” A:Application
  ls_output_options-xsfformat  = lc_flag.      ” Formatting ON

  ls_xsfparam_line-name  = lc_graphics.                     “#EC NOTEXT
  ls_xsfparam_line-value = lc_extract.                      “#EC NOTEXT
  APPEND ls_xsfparam_line TO ls_output_options-xsfpars.

  ls_xsfparam_line-name  = lc_contentid.                    “#EC NOTEXT
  ls_xsfparam_line-value = lc_enable.                       “#EC NOTEXT
  APPEND ls_xsfparam_line TO ls_output_options-xsfpars.

  “calling the smartform function module.

  CLEAR ls_control_parameters.

  CALL FUNCTION lv_function_name
      control_parameters = ls_control_parameters
      output_options     = ls_output_options
      user_settings      = ‘ ‘
      job_output_info    = ls_job_output_info
      formatting_error   = 1
      internal_error     = 2
      send_error         = 3
      user_canceled      = 4
      OTHERS             = 5.

check sy-subrc is initial.

  ls_xmloutput = ls_job_output_info-xmloutput.

  lt_html_raw  = ls_xmloutput-trfresult-content[].

  “image information.

  lt_graphics[] = ls_job_output_info-xmloutput-xsfgr[].

  “_____________getting the html format_______________________”

  CLEAR : lv_xstring,

  “converting from RAW fromat to XSTRING format.

  LOOP AT lt_html_raw INTO lv_xstring.

    CONCATENATE lv_html_xstring lv_xstring INTO lv_html_xstring
                                              IN BYTE MODE.

  “converting from XSTRING format to STRING format.

  lo_conv = cl_abap_conv_in_ce=>create( input = lv_html_xstring ).

  lo_conv->read( IMPORTING data = lv_html_temp ).

  “now we have our smart form data in the hmtl format .
  “we need to extract image information from the html string so that later
  “we can embed the image.

  “parse the html string tag by tag.
  CLEAR lt_part[].
  CALL METHOD cl_crm_html_parser=>parse_html_string
      iv_html                = lv_html_temp
      iv_all_tags_lower_case = lc_flag
      et_parts               = lt_part.

  “finding the source property value of the image (IMG SRC) in the
  “html string. so later we can use it when embedding the

  CLEAR ls_part.

  LOOP AT lt_part REFERENCE INTO ls_part WHERE tag = lc_img.

    CLEAR ls_attribute.

    READ TABLE ls_part->attributes REFERENCE INTO ls_attribute
       WITH TABLE KEY name = lc_src.
    IF sy-subrc IS INITIAL.

      IF ls_attribute->value(1) = ‘”‘.
        lv_len = STRLEN( ls_attribute->value ) – 2.
        lv_img_src = ls_attribute->value+1(lv_len).
        lv_img_src = ls_attribute->value.

      REPLACE ALL OCCURRENCES OF  ‘cid:’ IN lv_img_src WITH space.
      APPEND lv_img_src TO lt_imgsrc.



  CLEAR lv_len.

  lv_len = 1.
  “converting each image content into binary format.
  LOOP AT lt_graphics INTO ls_graphic.

    CLEAR : ls_gr_raw,

    LOOP AT ls_graphic-content INTO ls_gr_raw.

      CONCATENATE lv_html_xstring ls_gr_raw-line INTO lv_html_xstring IN BYTE MODE.

      CLEAR ls_gr_raw.


    CLEAR lv_imagename.

    CONCATENATE ls_graphic-graphics ‘.bmp’ INTO lv_imagename.

    “embedding the images inside the body.

    “here content id which is there in the html string and content id that\
    “we are sending in this internal table should be same.

    CLEAR ls_mail_body.

    ls_mail_body-is_attachment = lc_flag.

    ls_mail_body-content_bin = lv_html_xstring.

    CLEAR lv_img_src.
    READ TABLE lt_imgsrc INTO lv_img_src INDEX  lv_len.
    IF sy-subrc IS INITIAL.

      REPLACE FIRST OCCURRENCE OF lv_img_src IN lv_html_temp WITH lv_imagename.


    ls_mail_body-content_id  = lv_imagename.
    ls_mail_body-file_name = lv_imagename.

    ls_mail_body-mime_type = ls_graphic-httptype.

    APPEND  ls_mail_body TO lt_mail_body.

    lv_len = lv_len + 1.

    clear lv_html_xstring.


  “filling body of the mail.

  CLEAR ls_mail_body.

  ls_mail_body-content_ascii = lv_html_temp.

  ls_mail_body-mime_type = lc_text_html.

  ls_mail_body-file_name = lc_body_html.

  APPEND  ls_mail_body TO lt_mail_body.

  “filling to email address
  CLEAR ls_recep.
  ls_recep-address = lv_mail .
  APPEND ls_recep TO lt_to.

  “create mail object.

  CREATE OBJECT lo_create_mail.

  “moving the subject.
  MOVE ‘smart form as html mail’ TO lo_create_mail->subject.

  “moving the body
  MOVE lt_mail_body TO lo_create_mail->body.

  “moving to addresses
  MOVE lt_to TO lo_create_mail->to.

  “send the email.

  “calling method to send the email
  CALL METHOD cl_crm_email_utility_base=>send_email
      iv_mail_data       = lo_create_mail
      ev_send_request_id = lv_activity.



Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Hi Praveen and other SAP gurus,

      Thanks for the reply. But I'm having this requirement in ECC and not in CRM.

      Could you please provide some solution to the below problem:

      All the styles which I have mentioned in smartform is not getting displayed in the Email, ie, if some text is made bold, then it is not coming as bold text in email. Please suggest me a solution for the same as I need the solution urgently.

      Best regards

      Anurag Khanna

      Author's profile photo praveen kumar mannala
      praveen kumar mannala
      Blog Post Author

      hi one thing is not all email clients support style sheets. we have experienced problems if we send smart forms as hmtl to OUTLOOK2010. format is totally altered. at the same time, we send it  lotus notes, there mail format is fine.

      only one solution  , is we need to convert each smart form styles tags in to inline tags (move them from header section to body section as inline tags) manually. then it will work. but doing it through coding is not that much easy. Even i am waiting for another solutions.

      Author's profile photo Former Member
      Former Member

      Hi Praveen,

      Thanks for the reply. However, could you please specify as to how to convert smartstyles into inline tags...for example if I have one paragraph format for displaying bold text- "abc". Do you mean I should now write my text as "<b>abc</>"?

      Also please specify what to meant by saying to move from header section to body section.

      Thanks for your support. Awaiting for your valuable response.

      Best regards

      Anurag Khanna

      Author's profile photo praveen kumar mannala
      praveen kumar mannala
      Blog Post Author

      yes. what i mean is suppose there is a tag called img in the header section means

      <head><style><img... some properties like height width/> </style></head>.  in the body section it will be like <body> <img ></img></body>.

      we need to brign that height weight from img to body img tag. like this

      <img height = '' width= ''>. then it will work.

      Author's profile photo Former Member
      Former Member

      Hi Praveen,

      You mean to "cut" the tag from "head" section and "paste" that into "body" section of html. Suposse I have the following example:

      <head> <style> <!--sf{display:block}.ZTESTA a{color:#000000}img#LOGO{width:72pt;height:64pt;text-align:center}--></style></head>

      then it should be printed in the <body> tag and NOT in the <head> tag?

      Please let me know....

      Author's profile photo praveen kumar mannala
      praveen kumar mannala
      Blog Post Author


      Author's profile photo praveen kumar mannala
      praveen kumar mannala
      Blog Post Author

      just check it with small example.

      send small html code to your email client from crm.

      like <html><body><b>Anurag</b></body></html>. you can see anurag in bold letters when it reaches your email client.

      Author's profile photo Former Member
      Former Member

      Hi Praveen,

      Great work! Am using the same but I face an issue like...

      I have a graphics (CBOL) in my smartform bt when I try the program using the same Smartform, am nt getting the graphic in the email I send but just a box (w/o no picture) cant view the picture @ all. If am using a B&W bmp, its working fine.

      Please guide me where should i tune the code?

      Many thanks & regards.

      Author's profile photo Former Member
      Former Member

      Thanks Praveen for the Article.Its been long time so, I am not sure whether you are in touch with the topic now or not?

      I am facing  similar issue of converting Smartform (apearing in email body) to HTML. The scenario is: based on some condition, Action profile triggers and smartform and is sent as an email body./wp-content/uploads/2015/10/2015_10_06_122001_803770.pngI have enhanced the processing method and put line of codes given in above blog but email triggering itself didnot work.

      My query is, where can I make changes for getting smartform as HTML(Now plain text is appearing in Email)? Is it Smartform Itself or some settings needs to perform.