Skip to Content
This blog explains how to make use of Netweaver technologies smartforms and SAPConnect to prepare the content and send email.
Smartforms
Smart Forms provides graphical tool to prepare the content. Thus, a user who is familiar with the tool but has only rudimentary programming knowledge can configure forms with data from an SAP system for the relevant business processes. A function module gets generated when the smartform is activated. The logic of the form is mapped entirely in the Smart Form. To print a form, you call it from within an application program, in which you retrieve the application data to be merged into the form. As data retrieval and form logic are separated, you must only adapt the Smart Form if changes to the form logic are necessary. The application program passes the data via a function module interface to the Smart Form. For more information on smartforms refer to Reference section.
SAPConnect
SAPconnect provides a standard interface for external communication, which supports sending with telecommunication services, such as FAX, text message (pager/SMS), Internet mail, and X.400, as well as sending to printers and between different SAP systems. It enables external communication components to be connected to the SAP system. In this article we only deal with email functionality of SAPConnect.
Fusing both technologies together
Smartform can be configured to send an email or fax or print when the content is retrieved via the generated function module. However the sent email will be in the form of PDF document. Email notification in html format is achieved with the following steps:

  1. Create the smartform with relevant content.
  2. Activate the smartform to generate the function module.
  3. Use the generated function module to retrieve the content in html format.
  4. Transform the content (eg: html tags) as needed.
  5. Use the SAPConnect to send the email.

Creation of smartform
Create or modify a smartform using the transaction smartforms. You can have html content like links for images as shown below. image
Activate the form to generate the function module.
Code to fetch the smartform content in html format
Following code will get the smartform generated function module. Using the generated function module, it fetches the content in HTML format. From address can be SAP user id or an internal email address. Email address maintained SU01 transaction of the SAP user will appear in the from part of the email.

*&--------------------------------------------------------------------* *& Form SEND_SMARTFORM_HTML_EMAIL *&--------------------------------------------------------------------* * RETREIVES CONTENT FROM SMARTFORM AND SENDS EMAIL TO THE RECEIVERS *---------------------------------------------------------------------* * -->ET_RETURN ERROR OR INFORMATIONAL MESSAGES * -->RECEIVERS EMAIL RECEPIENTS * -->FORM_NAME FORM NAME * -->MAIL_SUBJECT EMAIL SUBJECT *---------------------------------------------------------------------* FORM SEND_SMARTFORM_HTML_EMAIL TABLES ET_RETURN TYPE BAPIRET2_TAB RECEIVERS STRUCTURE SOMLRECI1 "receivers USING IV_SMARTFORM TYPE TDSFNAME SEND_PARTNER TYPE BU_PARTNER "from address MAIL_SUBJECT TYPE SO_OBJ_DES. DATA: CONTROL_PARAMETERS TYPE SSFCTRLOP, OUTPUT_OPTIONS TYPE SSFCOMPOP, DOCUMENT_OUTPUT_INFO TYPE SSFCRESPD, JOB_OUTPUT_INFO TYPE SSFCRESCL, JOB_OUTPUT_OPTIONS TYPE SSFCRESOP, XSFPARAM_LINE TYPE SSFXSFP, P_HTML TYPE TRFRESULT, P_GRAPHICS TYPE TSF_XSF_GR, FORM_NAME TYPE RS38L_FNAM. " generated function module name DATA: WA_RETURN TYPE BAPIRET2. CONSTANTS: C_GR_DIR TYPE TDTEXT VALUE 'MYGRAPHICS/'. "#EC NOTEXT *SET SMARTFORM OUTPUT OPTIONS OUTPUT_OPTIONS-XSFCMODE = 'X'. "#EC NOTEXT OUTPUT_OPTIONS-XSF = 'X'. "#EC NOTEXT OUTPUT_OPTIONS-XSFOUTMODE = 'A'. "#EC NOTEXT OUTPUT_OPTIONS-XSFFORMAT = 'X'. "#EC NOTEXT CLEAR OUTPUT_OPTIONS-XSFOUTDEV. XSFPARAM_LINE-NAME = 'GRAPHICS'. "#EC NOTEXT XSFPARAM_LINE-VALUE = 'EXTRACT'. "#EC NOTEXT APPEND XSFPARAM_LINE TO OUTPUT_OPTIONS-XSFPARS. XSFPARAM_LINE-NAME = 'GRAPHICS-DIRECTORY'. "#EC NOTEXT XSFPARAM_LINE-VALUE = C_GR_DIR. APPEND XSFPARAM_LINE TO OUTPUT_OPTIONS-XSFPARS. XSFPARAM_LINE-NAME = 'CONTENT-ID'. "#EC NOTEXT XSFPARAM_LINE-VALUE = 'ENABLE'. "#EC NOTEXT APPEND XSFPARAM_LINE TO OUTPUT_OPTIONS-XSFPARS. * SILENT MODE ON OUTPUT_OPTIONS-TDIMMED = SPACE. OUTPUT_OPTIONS-TDNEWID = SPACE. CONTROL_PARAMETERS-NO_DIALOG = 'X'. "#EC NOTEXT * Get the generated function name of the smartform CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' "#EC NOTEXT EXPORTING FORMNAME = IV_SMARTFORM IMPORTING FM_NAME = FORM_NAME EXCEPTIONS NO_FORM = 1 NO_FUNCTION_MODULE = 2 OTHERS = 3. IF SY-SUBRC <> 0. * Error receiving the generated function module CLEAR WA_RETURN. MESSAGE E005 WITH IV_SMARTFORM INTO WA_RETURN-MESSAGE. WA_RETURN-TYPE = 'E'. "#EC NOTEXT INSERT WA_RETURN INTO TABLE ET_RETURN. EXIT. ENDIF. * Get the smartform content CALL FUNCTION FORM_NAME EXPORTING CONTROL_PARAMETERS = CONTROL_PARAMETERS OUTPUT_OPTIONS = OUTPUT_OPTIONS *pass other application specific parameters (eg order number, items ). IMPORTING DOCUMENT_OUTPUT_INFO = DOCUMENT_OUTPUT_INFO JOB_OUTPUT_INFO = JOB_OUTPUT_INFO JOB_OUTPUT_OPTIONS = JOB_OUTPUT_OPTIONS EXCEPTIONS FORMATTING_ERROR =1 INTERNAL_ERROR =2 SEND_ERROR =3 USER_CANCELED = 4. IF SY-SUBRC <> 0. * FAILED TO GET CONTENT FROM SMARTFORM CLEAR WA_RETURN. MESSAGE E012 WITH FORM_NAME SY-SUBRC INTO WA_RETURN-MESSAGE. INSERT WA_RETURN INTO TABLE ET_RETURN. EXIT. ENDIF. P_HTML = JOB_OUTPUT_INFO-XMLOUTPUT-TRFRESULT. P_GRAPHICS[] = JOB_OUTPUT_INFO-XMLOUTPUT-XSFGR[]. * send the extracted content all the recipients PERFORM SEND_HTML_EMAIL TABLES ET_RETURN RECEIVERS USING P_HTML P_GRAPHICS[] SEND_PARTNER MAIL_SUBJECT. ENDFORM. "SEND_SMARTFORM_HTML_EMAIL

Code to send the email
Following code will transform the html content into displayable format and send email to all the recipients. Note: This form also handles the images (static) defined in the smartform, as well as the images defined with html IMG tag (eg: URL link to image on the network).

*&--------------------------------------------------------------------* *& Form SEND_HTML_EMAIL *&--------------------------------------------------------------------* * Send the email provided the content and other details *---------------------------------------------------------------------* * -->P_RETURN Error messages * -->P_RECEIVERS emailr recipients * -->P_HTML html text * -->P_GRAPHICS html graphics if any * -->P_SUBJECT subject of the email *---------------------------------------------------------------------* FORM SEND_HTML_EMAIL TABLES P_RETURN TYPE BAPIRET2_TAB P_RECEIVERS STRUCTURE SOMLRECI1 USING P_HTML TYPE TRFRESULT P_GRAPHICS TYPE TSF_XSF_GR SEND_PARTNER TYPE BU_PARTNER P_SUBJECT TYPE SO_OBJ_DES. DATA: L_GRAPHIC TYPE SSF_XSF_GR. CONSTANTS: C_GR_DIR TYPE TDTEXT VALUE 'MYGRAPHICS/'. "#EC NOTEXT DATA: HTML_DATA TYPE TRFRESULT, GRAPHICS TYPE TSF_XSF_GR, LV_SENT_TO_ALL TYPE BOOLEAN, LV_SEND_ADDRESS TYPE ADR6-SMTP_ADDR, LI_SENDER TYPE REF TO IF_SENDER_BCS, RECEIVER TYPE SOMLRECI1. DATA: LO_BCS TYPE REF TO CL_BCS, LO_DOC_BCS TYPE REF TO CL_DOCUMENT_BCS, LO_MIME_HELPER TYPE REF TO CL_GBT_MULTIRELATED_SERVICE, LO_RECIPIENT TYPE REF TO IF_RECIPIENT_BCS. DATA: L_FILENAME TYPE STRING, LT_SOLI TYPE SOLI_TAB, LT_SOLIX TYPE SOLIX_TAB, LS_SOLI TYPE SOLI, LS_SOLIX TYPE SOLIX. DATA: L_HTML_RAW LIKE LINE OF HTML_DATA-CONTENT, HTML_XSTR TYPE XSTRING, HTML_STR TYPE STRING, HTML_LEN TYPEI, L_OFFSET TYPE I, L_LENGTH TYPE I, L_DIFF TYPE I, L_CONTENT_ID TYPE STRING, L_CONTENT_TYPE TYPE W3CONTTYPE, L_OBJ_LEN TYPE SO_OBJ_LEN, GR_XSTR TYPE XSTRING, L_GR_RAW TYPE BAPICONTEN, L_USERNAME TYPE UNAME, L_MAIL_ADDRESS TYPE AD_SMTPADR, WA_RETURN TYPE BAPIRET2. DATA: LV_SEND_REQ_BCS TYPE REF TO CX_SEND_REQ_BCS, LV_ADDRESS_BCS TYPE REF TO CX_ADDRESS_BCS, LV_GBT_MIME TYPE REF TO CX_GBT_MIME, LV_BCOM_MIME TYPE REF TO CX_BCOM_MIME, LV_DOCUMENT_BCS TYPE REF TO CX_DOCUMENT_BCS. CLEAR HTML_XSTR. LOOP AT P_HTML-CONTENT INTO L_HTML_RAW. CONCATENATE HTML_XSTR L_HTML_RAW INTO HTML_XSTR IN BYTE MODE. ENDLOOP. HTML_XSTR = HTML_XSTR(P_HTML-LENGTH). CALL FUNCTION 'SCP_TRANSLATE_CHARS' "#EC NOTEXT EXPORTING INBUFF = HTML_XSTR INCODE = '4110' " UTF-8 "#EC NOTEXT * OUTCODE = '0000' " ACTUAL CODEPAGE CSUBST = 'X' "#EC NOTEXT SUBSTC_SPACE = 'X' "#EC NOTEXT IMPORTING OUTBUFF = HTML_STR OUTUSED = HTML_LEN EXCEPTIONS OTHERS = 1. * CHANGE ENCODING UTF-8 TO LATIN1 REPLACE ALL OCCURRENCES OF 'UTF-8' IN HTML_STR WITH 'iso-8859-1' IGNORING CASE. "#EC NOTEXT *HACK THE HTML CODE GENERATED BY SARTFORM TO MAKE THE *EXTERNAL IMAGES APPEAR AS  TAG IN HTML REPLACE ALL OCCURRENCES OF '' IN HTML_STR WITH '/>' IGNORING CASE. "#EC NOTEXT REPLACE ALL OCCURRENCES OF '' IN HTML_STR WITH '' IGNORING CASE. "#EC NOTEXT REPLACE ALL OCCURRENCES OF '<' IN HTML_STR WITH '<' IGNORING CASE. "#EC NOTEXT REPLACE ALL OCCURRENCES OF '>' IN HTML_STR WITH '>' IGNORING CASE. "#EC NOTEXT HTML_LEN = STRLEN( HTML_STR ). L_OFFSET = 0. L_LENGTH = 255. WHILE L_OFFSET < HTML_LEN. L_DIFF = HTML_LEN - L_OFFSET. IF L_DIFF > L_LENGTH. LS_SOLI-LINE = HTML_STR+L_OFFSET(L_LENGTH). ELSE. LS_SOLI-LINE = 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 FILENAME = 'SAPWEBFORM.HTM' "#EC NOTEXT DESCRIPTION = 'SAP WEB FORM'. "#EC NOTEXT LOOP AT P_GRAPHICS INTO L_GRAPHIC. CLEAR GR_XSTR. LOOP AT L_GRAPHIC-CONTENT INTO L_GR_RAW. CONCATENATE GR_XSTR L_GR_RAW-LINE INTO GR_XSTR IN BYTE MODE. ENDLOOP. GR_XSTR = GR_XSTR(L_GRAPHIC-LENGTH). L_OFFSET = 0. L_LENGTH = 255. CLEAR LT_SOLIX[]. WHILE L_OFFSET < L_GRAPHIC-LENGTH. L_DIFF = L_GRAPHIC-LENGTH - L_OFFSET. IF L_DIFF > L_LENGTH. LS_SOLIX-LINE = GR_XSTR+L_OFFSET(L_LENGTH). ELSE. LS_SOLIX-LINE = GR_XSTR+L_OFFSET(L_DIFF). ENDIF. APPEND LS_SOLIX TO LT_SOLIX. ADD L_LENGTH TO L_OFFSET. ENDWHILE. CONCATENATE C_GR_DIR L_GRAPHIC-GRAPHICS '.BMP' INTO L_FILENAME. "#EC NOTEXT CONCATENATE C_GR_DIR L_GRAPHIC-GRAPHICS '.BMP' INTO L_CONTENT_ID. "#EC NOTEXT L_CONTENT_TYPE = L_GRAPHIC-HTTPTYPE. L_OBJ_LEN = L_GRAPHIC-LENGTH. *Add images to the email CALL METHOD LO_MIME_HELPER->ADD_BINARY_PART EXPORTING CONTENT = LT_SOLIX FILENAME = L_FILENAME EXTENSION = 'BMP' "#EC NOTEXT DESCRIPTION = 'GRAPHIC IN BMP FORMAT' "#EC NOTEXT CONTENT_TYPE = L_CONTENT_TYPE LENGTH = L_OBJ_LEN CONTENT_ID = L_CONTENT_ID. ENDLOOP. TRY. LO_DOC_BCS = CL_DOCUMENT_BCS=>CREATE_FROM_MULTIRELATED( I_SUBJECT = P_SUBJECT I_MULTIREL_SERVICE = LO_MIME_HELPER ). CATCH CX_DOCUMENT_BCS INTO LV_DOCUMENT_BCS. * ERROR HANDLING CLEAR WA_RETURN. WA_RETURN-TYPE = 'E'. "#EC NOTEXT MOVE LV_DOCUMENT_BCS->GET_LONGTEXT( ) TO WA_RETURN-MESSAGE. INSERT WA_RETURN INTO TABLE P_RETURN. EXIT. CATCH CX_BCOM_MIME INTO LV_BCOM_MIME. CLEAR WA_RETURN. WA_RETURN-TYPE = 'E'. "#EC NOTEXT MOVE LV_BCOM_MIME->GET_LONGTEXT( ) TO WA_RETURN-MESSAGE. INSERT WA_RETURN INTO TABLE P_RETURN. EXIT. CATCH CX_GBT_MIME INTO LV_GBT_MIME. CLEAR WA_RETURN. WA_RETURN-TYPE = 'E'. "#EC NOTEXT MOVE LV_GBT_MIME->GET_LONGTEXT( ) TO WA_RETURN-MESSAGE. INSERT WA_RETURN INTO TABLE P_RETURN. EXIT. ENDTRY. * REUSE THE CONTENT PREPARED FOR ALL RECEIVERS LOOP AT P_RECEIVERS INTO RECEIVER. L_MAIL_ADDRESS = RECEIVER-RECEIVER. * CREATE SEND_REQUEST TRY. LO_BCS = CL_BCS=>CREATE_PERSISTENT( ). LO_BCS->SET_DOCUMENT( I_DOCUMENT = LO_DOC_BCS ). CATCH CX_SEND_REQ_BCS INTO LV_SEND_REQ_BCS. CLEAR WA_RETURN. WA_RETURN-TYPE = 'E'. "#EC NOTEXT MOVE LV_SEND_REQ_BCS->GET_LONGTEXT( ) TO WA_RETURN-MESSAGE. INSERT WA_RETURN INTO TABLE P_RETURN. EXIT. ENDTRY. * CREATE SENDER CLASS CL_CAM_ADDRESS_BCS DEFINITION LOAD. TRY. IF L_USERNAME NS '@'. "#EC NOTEXT L_USERNAME = SEND_PARTNER . TRANSLATE L_USERNAME TO UPPER CASE. "#EC TRANSLANG LI_SENDER ?= CL_SAPUSER_BCS=>CREATE( L_USERNAME ). ELSE. DATA: L_FROM_MAIL_ADDRESS TYPE AD_SMTPADR. L_FROM_MAIL_ADDRESS = L_USERNAME. LI_SENDER ?= CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( I_ADDRESS_STRING = L_FROM_MAIL_ADDRESS ). ENDIF. CALL METHOD LO_BCS->SET_SENDER EXPORTING I_SENDER = LI_SENDER. CATCH CX_ADDRESS_BCS INTO LV_ADDRESS_BCS. * ERROR HANDLING CLEAR WA_RETURN. WA_RETURN-TYPE = 'E'. "#EC NOTEXT MOVE LV_ADDRESS_BCS->GET_LONGTEXT( ) TO WA_RETURN-MESSAGE. INSERT WA_RETURN INTO TABLE P_RETURN. EXIT. CATCH CX_SEND_REQ_BCS INTO LV_SEND_REQ_BCS. * FAILED TO ADD A SENDER CLEAR WA_RETURN. WA_RETURN-TYPE = 'E'. "#EC NOTEXT MOVE LV_SEND_REQ_BCS->GET_LONGTEXT( ) TO WA_RETURN-MESSAGE. INSERT WA_RETURN INTO TABLE P_RETURN. EXIT. EXIT. ENDTRY. * CREATE RECIPIENT TRY. LO_RECIPIENT = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( I_ADDRESS_STRING = L_MAIL_ADDRESS ). CATCH CX_ADDRESS_BCS INTO LV_ADDRESS_BCS. * ERROR HANDLING CONTINUE. ENDTRY. TRY. LO_BCS->ADD_RECIPIENT( I_RECIPIENT = LO_RECIPIENT ). CATCH CX_SEND_REQ_BCS INTO LV_SEND_REQ_BCS. * FAILED TO ADD A RECIPIENT CONTINUE. ENDTRY. * SEND TRY. * RECEIPTS ONLY FOR ERRORS CALL METHOD LO_BCS->SEND_REQUEST->SET_REQUESTED_STATUS EXPORTING I_REQUESTED_STATUS = 'N'. "#EC NOTEXT LV_SENT_TO_ALL = LO_BCS->SEND( ). CATCH CX_SEND_REQ_BCS INTO LV_SEND_REQ_BCS. CLEAR WA_RETURN. WA_RETURN-TYPE = 'E'. "#EC NOTEXT MOVE LV_SEND_REQ_BCS->GET_LONGTEXT( ) TO WA_RETURN-MESSAGE. INSERT WA_RETURN INTO TABLE P_RETURN. * ERROR HANDLING EXIT. ENDTRY. ENDLOOP. " END LOOP AT P_RECEIVERS COMMIT WORK. * set the success information CLEAR WA_RETURN. MESSAGE i013 INTO WA_RETURN-MESSAGE. "Email sent successfully INSERT WA_RETURN INTO TABLE P_RETURN. ENDFORM. "SEND_HTML_EMAIL

Adjust the look and feel of the email content
Make proper use of the smartstyles (transaction smartstyles) in the smartform to improve the look and feel of the email. Here is how a sample email looks. You can also use static images in the smartform. These images will come as multipart format. You can also make use of URL links in the smartforms to provide the link from email to the webapplication like webshop.
Sample email
image
Important transactions

  • Smartforms – create/edit smartforms and smart styles
  • Scot – Outgoing email management (Sending email, verify status etc)
  • sost – overview of sent emails
To report this post you need to login first.

55 Comments

You must be Logged on to comment or reply to a post.

  1. Hajira Syeda

    Hi,<br/>   Your article was very helpful, in generating the email to an external address in HTML format.<br/>   However, for some reason, the  email appears as an attahcment in the external mail id.<br/><br/>   When we asked SAP about the problem, they have responded saying that the program itself generates the attachment.<br/>   Could you please let me know as to what was wrong?<br/><br/>Here is the code sample we are using:<br/>***********************************************<br/><br/>REPORT  z_test_html_email  MESSAGE-ID 00.<br/><br/>**************Global Data*********************<br/>PARAMETER: p_email LIKE somlreci1-receiver OBLIGATORY, ” Reciever Email<br/>           ch_ext AS CHECKBOX TYPE char01.<br/><br/>** Macros for OBJCONT conversion*************Start of Selection*****************<br/>START-OF-SELECTION.<br/> Local data declarations&—-


    <br/>&      Form  SEND_SMARTFORM_HTML_EMAIL<br/>&–


    <br/>  RETREIVES CONTENT FROM SMARTFORM AND SENDS EMAIL TO THE RECEIVERS<br/>*


    <br/>      –>ET_RETURN  ERROR OR INFORMATIONAL MESSAGES<br/>*      –>RECEIVERS  EMAIL RECEPIENTS<br/>*      –>FORM_NAME  FORM NAME<br/>*      >MAIL_SUBJECT EMAIL SUBJECT<br/>*


    <br/>FORM send_smartform_html_email<br/>                  TABLES et_return    TYPE bapiret2_t<br/>                         receivers    STRUCTURE somlreci1 “receivers<br/>                  USING  iv_smartform TYPE  tdsfname<br/>                         send_partner TYPE bu_partner    “from address<br/>                         mail_subject TYPE so_obj_des.<br/><br/>  DATA: control_parameters   TYPE ssfctrlop,<br/>        output_options       TYPE ssfcompop,<br/>        document_output_info TYPE ssfcrespd,<br/>        job_output_info      TYPE ssfcrescl,<br/>        job_output_options   TYPE ssfcresop,<br/>        xsfparam_line        TYPE ssfxsfp,<br/>        p_html               TYPE trfresult,<br/>        p_graphics           TYPE tsf_xsf_gr,<br/>        form_name            TYPE rs38l_fnam.  ” generated function<br/><br/>  DATA: wa_return  TYPE bapiret2.<br/>  DATA: v_receiver TYPE ad_smtpadr.<br/><br/>SET SMARTFORM OUTPUT OPTIONS<br/>  output_options-tdnoprev   = ‘X’.                          “#EC NOTEXT<br/>  output_options-xsfcmode   = ‘X’.                          “#EC NOTEXT<br/>  output_options-xsf        = ‘X’.                          “#EC NOTEXT<br/>  output_options-xsfoutmode = ‘A’.                          “#EC NOTEXT<br/>  output_options-xsfformat  = ‘X’.                          “#EC NOTEXT<br/>  output_options-xsfaction  = ‘http://www.ashland.com‘.<br/>  CLEAR output_options-xsfoutdev.<br/><br/>  xsfparam_line-name  = ‘GRAPHICS’.                         “#EC NOTEXT<br/>  xsfparam_line-value = ‘EXTRACT’.                          “#EC NOTEXT<br/>  APPEND xsfparam_line TO output_options-xsfpars.<br/><br/>  xsfparam_line-name  = ‘GRAPHICS-DIRECTORY’.               “#EC NOTEXT<br/>  xsfparam_line-value = c_gr_dir.<br/>  APPEND xsfparam_line TO output_options-xsfpars.<br/><br/>  xsfparam_line-name  = ‘CONTENT-ID’.                       “#EC NOTEXT<br/>  xsfparam_line-value = ‘ENABLE’.                           “#EC NOTEXT<br/>  APPEND xsfparam_line TO output_options-xsfpars.<br/><br/>* SILENT MODE ON<br/>  output_options-tdimmed = space.<br/>  output_options-tdnewid = space.<br/>  control_parameters-no_dialog = ‘X’.                       “#EC NOTEXT<br/><br/>* Get the generated function name of the smartform<br/>  CALL FUNCTION ‘SSF_FUNCTION_MODULE_NAME’                  “#EC NOTEXT<br/>    EXPORTING<br/>      formname           = iv_smartform<br/>    IMPORTING<br/>      fm_name            = form_name<br/>    EXCEPTIONS<br/>      no_form            = 1<br/>      no_function_module = 2<br/>      OTHERS             = 3.<br/>  IF sy-subrc <> 0.<br/>*   Error receiving the generated function module<br/>    CLEAR wa_return.<br/>    MESSAGE e398 WITH iv_smartform INTO wa_return-message.<br/>    wa_return-type = ‘E’.                                   “#EC NOTEXT<br/>    INSERT wa_return INTO TABLE et_return.<br/>    EXIT.<br/>  ENDIF.<br/><br/>* Get the smartform content<br/>  CALL FUNCTION form_name<br/>    EXPORTING<br/>      control_parameters   = control_parameters<br/>      output_options       = output_options<br/>      p_v_subst_desc       = l_v_prod_dsc<br/>      p_v_shipto_country   = l_v_country<br/>    IMPORTING<br/>      document_output_info = document_output_info<br/>      job_output_info      = job_output_info<br/>      job_output_options   = job_output_options<br/>    EXCEPTIONS<br/>      formatting_error<br/>      =1<br/>      internal_error<br/>      =2<br/>      send_error<br/>      =3<br/>      user_canceled        = 4.<br/><br/>  IF sy-subrc <> 0.<br/>*   FAILED TO GET CONTENT FROM SMARTFORM<br/>    CLEAR wa_return.<br/>    MESSAGE e398  WITH form_name sy-subrc INTO wa_return-message.<br/>    INSERT wa_return INTO TABLE et_return.<br/>    EXIT.<br/>  ENDIF.<br/><br/>  p_html       = job_output_info-xmloutput-trfresult.<br/>  p_graphics[] = job_output_info-xmloutput-xsfgr[].<br/><br/>** send the extracted content all the recipients<br/>*  PERFORM send_html_email<br/>*              TABLES et_return<br/>*                     receivers<br/>*              USING  p_html<br/>*                     p_graphics[]<br/>*                     send_partner<br/>*                     mail_subject.<br/>  IF ch_ext = space.<br/>    v_receiver = sy-uname.<br/>  ELSE.<br/>    v_receiver = p_email.<br/>  ENDIF.<br/><br/>* III. Put HTML and images into mail object<br/>  PERFORM send_webform USING v_receiver<br/>                             p_html<br/>                             p_graphics[].<br/><br/>ENDFORM.                    “SEND_SMARTFORM_HTML_EMAIL<br/><br/><br/>following code will transform the html content into displayable format<br/>and send email to all the recipients.<br/>note: this form also handles the<br/>images (static) defined in the smartform, as well as the images defined<br/>with html img tag (eg: url link to image on the network).<br/><br/>&


    <br/>&      Form  SEND_HTML_EMAIL<br/>*&


    <br/>       Send the email provided the content and other details<br/>*


    <br/>      –>P_RETURN   Error messages<br/>*      –>P_RECEIVERS emailr recipients<br/>*      –>P_HTML     html text<br/>*      –>P_GRAPHICS html graphics if any<br/>*      >P_SUBJECT  subject of the email<br/>*


    <br/>FORM send_html_email<br/>                  TABLES p_return TYPE bapiret2_t<br/>                         p_receivers   STRUCTURE somlreci1<br/>                   USING p_html        TYPE trfresult<br/>                         p_graphics    TYPE tsf_xsf_gr<br/>                         send_partner TYPE bu_partner<br/>                         p_subject     TYPE so_obj_des.<br/><br/>  DATA: l_graphic TYPE ssf_xsf_gr.<br/>  CONSTANTS: c_gr_dir TYPE tdtext VALUE ‘MYGRAPHICS/’.      “#EC NOTEXT<br/>  DATA: html_data         TYPE trfresult,<br/>        graphics          TYPE tsf_xsf_gr,<br/>        lv_sent_to_all    TYPE boolean,<br/>        lv_send_address   TYPE adr6-smtp_addr,<br/>        li_sender         TYPE REF TO if_sender_bcs,<br/>        receiver          TYPE somlreci1.<br/><br/>  DATA: lo_bcs            TYPE REF TO cl_bcs,<br/>        lo_doc_bcs        TYPE REF TO cl_document_bcs,<br/>        lo_mime_helper    TYPE REF TO cl_gbt_multirelated_service,<br/>        lo_recipient      TYPE REF TO if_recipient_bcs.<br/><br/>  DATA: l_filename     TYPE string,<br/>        lt_soli        TYPE soli_tab,<br/>        lt_solix       TYPE solix_tab,<br/>        ls_soli        TYPE soli,<br/>        ls_solix       TYPE solix.<br/><br/>  DATA: l_html_raw     LIKE LINE OF html_data-content,<br/>        html_xstr      TYPE xstring,<br/>        html_str       TYPE string,<br/>        html_len       TYPE i,<br/>        l_offset       TYPE i,<br/>        l_length       TYPE i,<br/>        l_diff         TYPE i,<br/>        l_content_id   TYPE string,<br/>        l_content_type TYPE w3conttype,<br/>        l_obj_len      TYPE so_obj_len,<br/>        gr_xstr        TYPE xstring,<br/>        l_gr_raw       TYPE bapiconten,<br/>        l_username     TYPE uname,<br/>        l_mail_address TYPE ad_smtpadr,<br/>        wa_return TYPE bapiret2.<br/><br/>  DATA: lv_send_req_bcs    TYPE REF TO cx_send_req_bcs,<br/>        lv_address_bcs     TYPE REF TO cx_address_bcs,<br/>        lv_gbt_mime        TYPE REF TO cx_gbt_mime,<br/>        lv_bcom_mime       TYPE REF TO cx_bcom_mime,<br/>        lv_document_bcs    TYPE REF TO cx_document_bcs.<br/><br/>  CLEAR html_xstr.<br/>  LOOP AT p_html-content INTO l_html_raw.<br/>    CONCATENATE html_xstr l_html_raw INTO html_xstr IN BYTE MODE.<br/>  ENDLOOP.<br/>  html_xstr = html_xstr(p_html-length).<br/><br/>  CALL FUNCTION ‘SCP_TRANSLATE_CHARS’                       “#EC NOTEXT<br/>    EXPORTING  inbuff       = html_xstr<br/>               incode       = ‘4110’       ” UTF-8 “#EC NOTEXT<br/>              OUTCODE      = ‘0000’       ” ACTUAL CODEPAGE<br/>               csubst       = ‘X’                           “#EC NOTEXT<br/>               substc_space = ‘X’                           “#EC NOTEXT<br/>    IMPORTING  outbuff      = html_str<br/>               outused      = html_len<br/>    EXCEPTIONS OTHERS       = 1.<br/><br/>* CHANGE ENCODING UTF-8 TO LATIN1<br/>  REPLACE ALL OCCURRENCES OF ‘UTF-8’ IN html_str<br/>          WITH ‘iso-8859-1’ IGNORING CASE.                  “#EC NOTEXT<br/><br/>HACK THE HTML CODE GENERATED BY SARTFORM TO MAKE THE<br/>EXTERNAL IMAGES APPEAR AS !! TAG IN HTML<br/>  REPLACE ALL OCCURRENCES OF ‘<IMG’ IN html_str<br/>          WITH ‘<IMG’ IGNORING CASE.                        “#EC NOTEXT<br/><br/>  REPLACE ALL OCCURRENCES OF ‘/>’ IN html_str<br/>          WITH ‘/>’ IGNORING CASE.                          “#EC NOTEXT<br/><br/>  REPLACE ALL OCCURRENCES OF ‘</A>’ IN html_str<br/>          WITH ” IGNORING CASE.                            “#EC NOTEXT<br/><br/>  REPLACE ALL OCCURRENCES OF ‘<‘ IN html_str<br/>          WITH ‘<‘ IGNORING CASE.                           “#EC NOTEXT<br/><br/>  REPLACE ALL OCCURRENCES OF ‘>’ IN html_str<br/>          WITH ‘>’ IGNORING CASE.                           “#EC NOTEXT<br/><br/>  html_len = STRLEN( html_str ).<br/>  l_offset = 0.<br/>  l_length = 255.<br/><br/>  WHILE l_offset < html_len.<br/>    l_diff = html_len – l_offset.<br/>    IF l_diff > l_length.<br/>      ls_soli-line = html_strl_offset(l_length).<br/>    ELSE.<br/>      ls_soli-line = html_strl_offset(l_diff).<br/>    ENDIF.<br/>    APPEND ls_soli TO lt_soli.<br/>    ADD l_length TO l_offset.<br/>  ENDWHILE.<br/><br/>  CREATE OBJECT lo_mime_helper.<br/><br/>  CALL METHOD lo_mime_helper->set_main_html<br/>    EXPORTING<br/>      content     = lt_soli<br/>      filename    = ‘SAPWEBFORM.HTM’                        “#EC NOTEXT<br/>      description = ‘SAP WEB FORM’.                         “#EC NOTEXT<br/><br/>  LOOP AT p_graphics INTO l_graphic.<br/>    CLEAR gr_xstr.<br/>    LOOP AT l_graphic-content INTO l_gr_raw.<br/>      CONCATENATE gr_xstr l_gr_raw-line INTO gr_xstr IN BYTE MODE.<br/>    ENDLOOP.<br/>    gr_xstr = gr_xstr(l_graphic-length).<br/>    l_offset = 0.<br/>    l_length = 255.<br/>    CLEAR lt_solix[].<br/><br/>    WHILE l_offset < l_graphic-length.<br/>      l_diff = l_graphic-length – l_offset.<br/>      IF l_diff > l_length.<br/>        ls_solix-line = gr_xstrl_offset(l_length).<br/>      ELSE.<br/>        ls_solix-line = gr_xstrl_offset(l_diff).<br/>      ENDIF.<br/>      APPEND ls_solix TO lt_solix.<br/>      ADD l_length TO l_offset.<br/>    ENDWHILE.<br/><br/>    CONCATENATE c_gr_dir l_graphic-graphics ‘.BMP’ INTO l_filename.<br/>    CONCATENATE c_gr_dir l_graphic-graphics ‘.BMP’ INTO l_content_id.<br/>    l_content_type = l_graphic-httptype.<br/>    l_obj_len      = l_graphic-length.<br/><br/>*   Add images to the email<br/>    CALL METHOD lo_mime_helper->add_binary_part<br/>      EXPORTING<br/>        content      = lt_solix<br/>        filename     = l_filename<br/>        extension    = ‘BMP’                                “#EC NOTEXT<br/>        description  = ‘GRAPHIC IN BMP FORMAT’              “#EC NOTEXT<br/>        content_type = l_content_type<br/>        length       = l_obj_len<br/>        content_id   = l_content_id.<br/><br/>  ENDLOOP.<br/><br/>  TRY.<br/>      lo_doc_bcs = cl_document_bcs=>create_from_multirelated(<br/>                                  i_subject          = p_subject<br/>                                  i_multirel_service = lo_mime_helper )<br/>.<br/><br/>    CATCH cx_document_bcs INTO lv_document_bcs.<br/>*   ERROR HANDLING<br/>      CLEAR wa_return.<br/>      wa_return-type = ‘E’.                                 “#EC NOTEXT<br/>      MOVE lv_document_bcs->get_longtext( ) TO wa_return-message.<br/>      INSERT wa_return INTO TABLE p_return.<br/>      EXIT.<br/><br/>    CATCH cx_bcom_mime INTO lv_bcom_mime.<br/>      CLEAR wa_return.<br/>      wa_return-type = ‘E’.                                 “#EC NOTEXT<br/>      MOVE lv_bcom_mime->get_longtext( ) TO wa_return-message.<br/>      INSERT wa_return INTO TABLE p_return.<br/>      EXIT.<br/><br/>    CATCH cx_gbt_mime INTO lv_gbt_mime.<br/>      CLEAR wa_return.<br/>      wa_return-type = ‘E’.                                 “#EC NOTEXT<br/>      MOVE lv_gbt_mime->get_longtext( ) TO wa_return-message.<br/>      INSERT wa_return INTO TABLE p_return.<br/>      EXIT.<br/><br/>  ENDTRY.<br/><br/>* REUSE THE CONTENT PREPARED FOR ALL RECEIVERS<br/>  LOOP AT p_receivers  INTO receiver.<br/>    l_mail_address = receiver-receiver.<br/>* CREATE SEND_REQUEST<br/>    TRY.<br/>        lo_bcs = cl_bcs=>create_persistent( ).<br/>        lo_bcs->set_document( i_document = lo_doc_bcs ).<br/><br/>      CATCH cx_send_req_bcs INTO lv_send_req_bcs.<br/>        CLEAR wa_return.<br/>        wa_return-type = ‘E’.                               “#EC NOTEXT<br/>        MOVE lv_send_req_bcs->get_longtext( ) TO wa_return-message.<br/>        INSERT wa_return INTO TABLE p_return.<br/>        EXIT.<br/>    ENDTRY.<br/><br/>* CREATE SENDER<br/>    CLASS cl_cam_address_bcs DEFINITION LOAD.<br/>    TRY.<br/>        IF l_username NS ‘@’.                               “#EC NOTEXT<br/>          l_username = send_partner .<br/>          TRANSLATE l_username TO UPPER CASE.            “#EC TRANSLANG<br/>          li_sender ?= cl_sapuser_bcs=>create( l_username ).<br/>        ELSE.<br/>          DATA: l_from_mail_address TYPE ad_smtpadr.<br/>          l_from_mail_address = l_username.<br/>          li_sender ?=<br/>            cl_cam_address_bcs=>create_internet_address(<br/>              i_address_string = l_from_mail_address ).<br/>        ENDIF.<br/><br/>        CALL METHOD lo_bcs->set_sender<br/>          EXPORTING<br/>            i_sender = li_sender.<br/><br/>      CATCH cx_address_bcs INTO lv_address_bcs.<br/>*     ERROR HANDLING<br/>        CLEAR wa_return.<br/>        wa_return-type = ‘E’.                               “#EC NOTEXT<br/>        MOVE lv_address_bcs->get_longtext( ) TO wa_return-message.<br/>        INSERT wa_return INTO TABLE p_return.<br/>        EXIT.<br/><br/>      CATCH cx_send_req_bcs INTO lv_send_req_bcs.<br/>*   FAILED TO ADD A SENDER<br/>        CLEAR wa_return.<br/>        wa_return-type = ‘E’.                               “#EC NOTEXT<br/>        MOVE lv_send_req_bcs->get_longtext( ) TO wa_return-message.<br/>        INSERT wa_return INTO TABLE p_return.<br/>        EXIT.<br/>        EXIT.<br/>    ENDTRY.<br/>* CREATE RECIPIENT<br/><br/>    TRY.<br/>        lo_recipient = cl_cam_address_bcs=>create_internet_address(<br/>                            i_address_string = l_mail_address ).<br/>      CATCH cx_address_bcs INTO lv_address_bcs.<br/>*     ERROR HANDLING<br/>        CONTINUE.<br/>    ENDTRY.<br/><br/>    TRY.<br/>        lo_bcs->add_recipient( i_recipient = lo_recipient ).<br/>      CATCH cx_send_req_bcs INTO lv_send_req_bcs.<br/>*   FAILED TO ADD A RECIPIENT<br/>        CONTINUE.<br/>    ENDTRY.<br/><br/>* SEND<br/>    TRY.<br/>*     RECEIPTS ONLY FOR ERRORS<br/>        CALL METHOD lo_bcs->send_request->set_requested_status<br/>          EXPORTING<br/>            i_requested_status = ‘N’.                       “#EC NOTEXT<br/>        lv_sent_to_all = lo_bcs->send( ).<br/><br/>      CATCH cx_send_req_bcs INTO lv_send_req_bcs.<br/>        CLEAR wa_return.<br/>        wa_return-type = ‘E’.                               “#EC NOTEXT<br/>        MOVE lv_send_req_bcs->get_longtext( ) TO wa_return-message.<br/>        INSERT wa_return INTO TABLE p_return.<br/>*   ERROR HANDLING<br/>        EXIT.<br/>    ENDTRY.<br/><br/>  ENDLOOP.     ”  END LOOP AT P_RECEIVERS<br/><br/>  COMMIT WORK.<br/><br/>* set the success information<br/>  CLEAR wa_return.<br/>  MESSAGE i398 INTO  wa_return-message. “Email sent successfully<br/>  INSERT wa_return INTO TABLE p_return.<br/><br/>ENDFORM.                    “SEND_HTML_EMAIL<br/><br/><br/><br/>*—


    <br/>FORM send_webform USING p_recipient   TYPE ad_smtpadr<br/>                        p_html        TYPE trfresult<br/>                        p_graphics    TYPE tsf_xsf_gr.<br/><br/>  DATA: lo_bcs            TYPE REF TO cl_bcs,<br/>        lo_doc_bcs        TYPE REF TO cl_document_bcs,<br/>        lo_mime_helper    TYPE REF TO cl_gbt_multirelated_service,<br/>        lo_recipient      TYPE REF TO if_recipient_bcs.<br/><br/>  DATA: l_graphic TYPE ssf_xsf_gr.<br/>  DATA: l_filename     TYPE string,<br/>        lt_soli        TYPE soli_tab,<br/>        lt_solix       TYPE solix_tab,<br/>        ls_soli        TYPE soli,<br/>        ls_solix       TYPE solix.<br/><br/>  DATA: l_html_raw     LIKE LINE OF p_html-content,<br/>        html_xstr      TYPE xstring,<br/>        html_str       TYPE string,<br/>        html_len       TYPE i,<br/>        l_offset       TYPE i,<br/>        l_length       TYPE i,<br/>        l_diff         TYPE i,<br/>        l_content_id   TYPE string,<br/>        l_content_type TYPE w3conttype,<br/>        l_obj_len      TYPE so_obj_len,<br/>        gr_xstr        TYPE xstring,<br/>        l_gr_raw       TYPE bapiconten,<br/>        l_subject      TYPE so_obj_des,<br/>        l_username     TYPE uname,<br/>        l_mail_address TYPE ad_smtpadr.<br/><br/>  DATA: l_send_exception TYPEREF TO cx_root,<br/>        l_reason         TYPE string.<br/><br/>  CLEAR html_xstr.<br/>  LOOP AT p_html-content INTO l_html_raw.<br/>    CONCATENATE html_xstr l_html_raw INTO html_xstr IN BYTE MODE.<br/>  ENDLOOP.<br/>  html_xstr = html_xstr(p_html-length).<br/>  CALL FUNCTION ‘SCP_TRANSLATE_CHARS'<br/>    EXPORTING  inbuff       = html_xstr<br/>               incode       = ‘4110’                        ” utf-8<br/>*              OUTCODE      = ‘0000’       ” actual codepage<br/>               csubst       = ‘X'<br/>               substc_space = ‘X'<br/>    IMPORTING  outbuff      = html_str<br/>               outused      = html_len<br/>    EXCEPTIONS OTHERS       = 1.<br/><br/>* change encoding utf-8 to latin1<br/>  REPLACE ALL OCCURRENCES OF ‘utf-8’ IN html_str WITH ‘latin1’.  ” ???<br/>                                                            “#EC NOTEXT<br/><br/>  html_len = STRLEN( html_str ).<br/><br/>  l_offset = 0.<br/>  l_length = 255.<br/>  WHILE l_offset < html_len.<br/>    l_diff = html_len – l_offset.<br/>    IF l_diff > l_length.<br/>      ls_soli-line = html_strl_offset(l_length).<br/>    ELSE.<br/>      ls_soli-line = html_strl_offset(l_diff).<br/>    ENDIF.<br/>    APPEND ls_soli TO lt_soli.<br/>    ADD l_length TO l_offset.<br/>  ENDWHILE.<br/><br/>  CREATE OBJECT lo_mime_helper.<br/>  CALL METHOD lo_mime_helper->set_main_html<br/>    EXPORTING<br/>      content     = lt_soli<br/>      filename    = ‘sapwebform.htm'<br/>      description = ‘SAP Web Form’.                         “#EC NOTEXT<br/><br/>  LOOP AT p_graphics INTO l_graphic.<br/>    CLEAR gr_xstr.<br/>    LOOP AT l_graphic-content INTO l_gr_raw.<br/>      CONCATENATE gr_xstr l_gr_raw-line INTO gr_xstr IN BYTE MODE.<br/>    ENDLOOP.<br/>    gr_xstr = gr_xstr(l_graphic-length).<br/>    l_offset = 0.<br/>    l_length = 255.<br/>    CLEAR lt_solix[].<br/>    WHILE l_offset < l_graphic-length.<br/>      l_diff = l_graphic-length – l_offset.<br/>      IF l_diff > l_length.<br/>        ls_solix-line = gr_xstrl_offset(l_length).<br/>      ELSE.<br/>        ls_solix-line = gr_xstrl_offset(l_diff).    TRANSLATE l_username TO UPPER CASE.                     “#EC <br/>    TRY.<br/>        lo_recipient = cl_sapuser_bcs=>create( l_username ).<br/>      CATCH cx_address_bcs INTO l_send_exception.<br/>     error handling*************************************************

    (0) 
    1. Pavan Bayyapu Post author
      Dear Hajira,
      Can you check the content type(text/html or text/plain) of the received mail. Normally this is visible in the options section based on the email client. If it is text/plain, mail client may not show html, so it could place in attachment section.

      Based on the CRM version you have, you can also have a look at cl_crm_email_utility=>get_body_part_from_editor
      and  cl_crm_email_utility=>send_email . These two methods give some idea on how to compose multipart message and send it.

      Best regards,
      pavan

      (0) 
      1. sireesha Borra
        Hi Pavan,
        your weblog is very helpful, and i also have requirement of sending html format of smart form output to KM repository or to any file system of EP6.0.
        If u have any solution regarding this, please put it here.
        Thanks in advance,
        Regards,
        sireesha.
        (0) 
        1. Pavan Bayyapu Post author
          Hi sireesha,
          If you like to save the document to KM, you can have a look at the class CL_CRM_DOCUMENTS (in CRM).
          I donot have knowledge on EP6 file system.

          Best regards,
          pavan

          (0) 
          1. Lee Zukor
            Pavan,
            I am attempting to use the code you’ve shared to send an smartform email in HTML format from our ERP system.  The email came through with the graphics as an attachment.  The body of the email started with this message:

            “Service cannot be reached
            What has happened?
            URL http://localhost/SAP/BC/BSP/SAP/SMART_FORMS/DEFAULT.CSS call was terminated because the corresponding service is not available.

            Note

                * The termination occurred in system DEV with error code 403 and for the reason Forbidden.
                * The selected virtual host was 0 .

            What can I do?

                * Please select a valid URL.
                * If you do not yet have a user ID, contact your system administrator.

            ErrorCode:ICF-NF-http-c:001-u:LEEZ-l:E-i:cujo_DEV_05-v:0-s:403-r:Forbidden

            HTTP 403 – Forbidden

            Your SAP Internet Communication Framework Team”

            Pavan, can you tell me what this message might mean?
            FYI, we are on Basis 640 patch 14.
            thanks,
            Lee Zukor  leez@pcf.com

            (0) 
            1. Pavan Bayyapu Post author
              Hi Lee,
              Can you try the following:
              Get the host name and http port of the server which is hosting the smartforms.
              you can get this by going to transaction SICF or contact BASIS admin.
              then try the URL and see whether it works
              http://host:port/SAP/BC/BSP/SAP/SMART_FORMS/DEFAULT.CSS

              I guess you have the following problem:

              SICF http server and port are not configured
              Meaning certain services (in this case sap/bc/bsp/sap/smar_forms) should run in order for the functionality to work.

              Your basis administrator might provide more info on this

              Regards,
              pavan

              (0) 
      2. J. Ouddeken
        Hi,
        I have found this log very helpful too, however, when sending a simple Smartform everything goes ok. But when the form contains graphics (e.g. company-logo) the mail gets sent but the html-part as well as the graphics part get sent as separate attachments. I have had a look at the cl_crm_email_utility but that wasn’t very helpful.

        Do any of you have suggestions how to fix this ?

        Best regards,
        Jos

        (0) 
        1. Pavan Bayyapu Post author
          Hi Jos,
          Somehow this problem is occuring for few users. Can we collect the SAP basis version of the users who are having this issue. This way we can isolate the problem.

          I could not reproduce the problem on our servers. i would like to debug, if there is way to.

          Best regards,
          pavan

          (0) 
          1. Anonymous
            YES!!!! I found the solution!!

            First of all: Congrats for you great job. This programm is realy helpful.

            I found a not for this topic:
            Microsoft Knowledge Base Article – 323482 states that starting with Exchange 2000 servers the behaviour of displaying a file attachment instead the message in the body of the email occurs when the “content- disposition” header of a multipart message is used with the parameter “filename”.  The resolution is to not use the parameter filename. This issue comes when you use MS Exchange 2000 or Exchange 2003 server.

            So if you do not hand over the filename in these two function calls, everything works fine:
            CALL METHOD LO_MIME_HELPER->SET_MAIN_HTML
            CALL METHOD LO_MIME_HELPER->ADD_BINARY_PART

            Hope this helps
            Kind Regards
            Stefan

            (0) 
            1. Brad Herzog
              Have you every tried to forward/reply to an email created in this fashion? I have implemented the code to send the email and removed the filename to these two calls and the email is created. However, when I try to forward the email it doesn’t move the mail body down so there is room at the top of the email to enter in new text. Basically, the body of the email remains fixed in the same location, and if I type text it is hidden behind the original email body.
              (0) 
            2. Chris Franz
              Hi Stefan,
              I have a similar problem: a graphic that is set as a background graphic on page level in smartforms is not displayed in the email. Additionally a normal graphic arrives as an attachment. I also used the code from Pavan.
              I also tried not to pass the filename as you said, but the result is only that the attached graphic has the name ‘filename’.
              Maybe you have a hint for me ?
              Kind regards,
              Chris.
              (0) 
  2. Sandra Lawrence
    Hi,

    This weblog was fanastic.  The emails are coming out perfectly except for one problem.

    We are sending emails to all our employees who met certain criteria with a cc to their manager.  The email to the first employee was formatted as per the Smartform style with bolding and the correct font, however all subsequent emails lose all of the formatting including fonts, bolding and indentation.  We use Lotus Notes for our emails, however it is not caused by Notes, the formating is already lost when viewing the email in SOST.

    I have looked at the content of the p_html (job_output_info-xmloutput-trfresult) variable and for the first email it’s length is approx. 12300 for the next emails it is only 5600.

    I thought it could be that some variable was not initialised, I have now initialised all inputs to the Smartform function and this hasn’t made any difference.

    Any suggestions?

    Thanks
    Sandra Lawrence
    Canberra, Australia

    (0) 
    1. Pavan Bayyapu Post author
      Hi Sandra,
      Happy to see someone making use of the weblog.
      Sorry, i could not respond due to other commitments.

      Based on the information you provided, it looks like smartform generated function (SSF_FUNCTION_MODULE_NAME) is not returning the mime related content on successive calls.

      Have a break point and check the input params to the smartforms generated function module. If they are exactly same (except the employee id or so), then it should return the same content including the styles etc. Only exception is that the conditions used in the smartform could influence the content.

      To bypass this problem, you could consider caching the mimes etc.

      Best regards,
      pavan

      (0) 
      1. Hakan Demirbilek
        Hi,

        It’s a great weblog. Thanks for sharing it with us. I have had the same problem with smartforms. When you call the function module in a loop the system does not generate the same content. I have found out that you have to set output format to XSF in Form Attributes.

        (0) 
  3. Sanman Kelkar
    Hello Sir,
    Your blog has been helpful but i am still facing some issues.

    I am working in Internet Sales in CRM. Whenever i create a order in the web, the details of the order should go as an external mail to the user through CRM. I am using a copy of the standard smartform CRM_ORDER_CONFIRMATION_01 which is attached to the action definition.

    Form Name ZORDER01
    Processing Class
    CL_DOC_PROCESSING_CRM_ORDER
    Processing method CRM_ORDER_EXEC_SMART_FORM
    Archive Mode Mail Only

    I have not modified the method as of now. I just tested the html by creating the standalone print program and form as mentioned in your blog. The problems are.

    1 The links i insert appear as it is. For eg. If i try to insert a ‘google link, I type
    Google
    in the text. But in the email it appears as it is.

    2 The same goes with the image. For eg if i type , This also appears as it is in the email.

    3 The logo which i uploaded is also not getting printed. Just a small square appears.

    The email is just going with the text with color fonts.
    My scot settings are as follows

    Internet
    SAPscript/Smart Forms PDF
    ABAP List HTM
    Business Object/Link HTM
    RAW Text TXT

    Please help me in this regard. My email id is sanmank@yahoo.com

    Thanks and Regards,
    Sanman Kelkar

    (0) 
    1. Pavan Bayyapu Post author
      Hi,
      I donot think the method CRM_ORDER_EXEC_SMART_FORM
      of class
      CL_DOC_PROCESSING_CRM_ORDER
      is intended to send html emails. I think it can be used for text based on pdf mails.
      If you are dealing with CRM 5.0, you can try CRM_ISA_AUCTION_SMART_FORM. Which is intended for html emails.
      You can alternatively copy the crm_isa_auction_smart_form method and modify it to your requirements.

      Hope this helps.

      thanks,
      pavan

      (0) 
  4. Mathangi Balakrishnan
    Hi Pavan,

    I was looking through the weblog. I have a requirement in my project. I need to display a URL > 255 characters  and send it as mail thru Smartform. The URL is generated by a function module within the Smart form in CRM. So it is stored in a variable say g_url. THe problem is that the URL gets truncated after 255 characters in the Mail.

    Could you please provide a solution for this. It is quite urgent.

    Thanks in advance!
    Mathangi

    (0) 
      1. Marcin Jaromin
        Hello,

        I have faced the same problem.
        The source of it is not a definition of variable but limitiations of technology…

        Please see SAP Note 485296 – Maximum string output length of 255 characters

        Do you have any suggestions how to put an URL longer than 255 chars in Smartform?

        Best regards,
        Marcin Jaromin

        (0) 
    1. Mathangi Balakrishnan
      Pavan,

      The problem is not with the data type. I am currently using type string and I also tried out character types like 1024 chars etc. When we debug the form, the entire URL which is of length 532 characters appears perfectly. But when I display the same in the PC editor and send the Smart form as Email, only 255 characters of the URL appear. The rest is truncated.

      Hope you got the problem now. Do you have any solution for this?

      (0) 
  5. Hakan Demirbilek
    Hi Pavan;
    I have used your sample code in my program. It works great when I run it online but if I schedule it, I receive an empty mail… Do you have any idea what causes this?
    (0) 
  6. Andreas Lang
    Hi,

    is it possible to use this functionality also in a background processing ? Means could I use it for example to send a oderconfirmation directly from the outputmessages in the VA01?

    (0) 
    1. Pavan Bayyapu Post author
      Hi,
      Here is what you need to do:
      1. Move the email generation code to a function module
      2. Launch the function module in new task.
      CALL FUNCTION func STARTING NEW TASK task .

      Hope I understood your requirement correctly.

      Thanks,
      pavan

      (0) 
  7. Maria João Paulo Rocha
    Hi,
    First I want to thanks for the helpful weblog.

    We are using the SAP Support Desk, and when a new message arrives, we send a plain message, by email, to inform the user that he’s message was received in the support desk.
    Now, we want to improve the layout of the email message using smart forms.

    When I do a reply, the html becomes “editable”!
    Can you help please?
    Thanks in advance,
    Maria João Rocha

    (0) 
    1. Pavan Bayyapu Post author
      Hi Maria,
      I donot think there is a way to prevent user from editing the html. But the support agent should cross check whether the contents are modified before providing service.

      Another way might
      Best regards,
      pavan

      (0) 
      1. Brent Curtis
        Hi Pavan,

        I think I basically have the same question.  It isn’t so much a concern of editing the email but the format of the email itself.  When I go to reply or forward, the html doesn’t shift down the page under the to/from history line and allow for you to enter a message.  It stays at the top of the page and any additional message you type is hidden behind the html objects. 

        Thanks for any help with this.

        Brent

        (0) 
        1. Pavan Bayyapu Post author
          Sorry Brent. Now i got the problem. Looks like the mime packaging needs little tuneup.
          I verified format of other html emails i received, and they behave differently.
          If someone already discovered the fix, please post it.
          I am no longer working on the project to experiment.
          Best regards,
          pavan
          (0) 
  8. Chris Franz
    Hi Pavvan,
    I used your coding for sending an email from ERP. My problem is, when I set a graphic as background graphic on page level in the smartform it is not displayed in the mail. When I add a graphic somewhere on the page it always comes first in the mail and not where I positioned it.
    Another problem is that tables in the main window are not displayed correctly. Frames are missing and there is no space between the columns.
    I hope you can help me with that.
    Kind regards,
    Chris.
    (0) 
    1. Pavan Bayyapu Post author
      Hi Chris,
      My advise here is to isolate the html in the email. Probably through “save as” menu in outlook.
      Then try to change the html to bring the gif in the background.

      Do the same change(transformation) in the coding where we manipulated the image and url tags. Just before pushing into the email envelop the change needs to be done.
      About the table issues you mentioned: These might be linked to smartforms tool usage. i don’t have the landscape to simlate the problem currently.
      Thanks,
      pavan

      (0) 
    2. Santosh Kotra
      Hi Cris,

      I too have a same development, where i need to display a table in main window. Here it is not displaying any Frames and also all the formatting done from smartstyles is also not visible. If you solved your problem, please do help me.

      Regards,
      Santosh Kotra

      (0) 
  9. Amol Guttal
    Hello,

    I have a problem.I want to display data from a complaint transaction in an e-mail using smart forms.
    I want to display both header and item data.

    We were able to display the header data by inserting the form fields ORDERMADM_H-GUID etc(header table)in the general attribute section of the mail content(created a new text in the main section of pages and windows of a smart form).

    But when we try to display the Item data by inserting the form field ORDERADM_I-GUID etc and hit on check it is giving the following error.

    “@8O@     MAILCONTENT     “ORDERADM_I” is a table without a header line and therefore has no component called “GUID”.”

    @8R@     MAILCONTENT     Field orderadm_I-GUID has no defined value

    Can you please let us know where we are missing on this ?

    Amol

    (0) 
  10. Jan Penninkhof
    This solution used to work very well, until Microsoft decided to start using the Word Render-engine for HTML email instead of IE7. That’s right. Instead of taking advantage of Internet Explorer 7, Outlook 2007 uses the very limited support for HTML and CSS that is built into Word 2007 to display HTML email messages.

    The limitations imposed by Word 2007 are described in detail on http://msdn2.microsoft.com/en-us/library/aa338201.aspx, but here are a few highlights:

        * no support for background images (HTML or CSS)
        * no support for forms
        * no support for Flash, or other plugins
        * no support for CSS floats
        * no support for replacing bullets with images in unordered lists
        * no support for CSS positioning
        * no support for animated GIFs

    In short, unless your HTML emails are very, very simple, you’re going to run into problems with Outlook 2007. Unfortunately, the CSS sheets generated by SEND_HTML_EMAIL aren’t that simple and output in Outlook 2007 looks quite bad.

    I hope Microsoft will come to it’s senses and will start using IE7 as Outlook’s render engine. But until then, I would like to urge SAP to look into this, and see if the stylesheets can be made simpler and Outlook 2007 compliant.

    (0) 
  11. Reema Shahbazkar
    Hi Pavan,

    Firstly I must appreciate the great work that you have done.
    I did exactly what you have mentioned in the blog.
    I have used a img (same as you have mentioned in the blog), a button ()tag and a hyperlink () tag in the text of the smartform.

    The email is sent but when I display the document in SOST transaction, it opens it as a .mht and not.htm
    Moreover everything appears as text instead of HTML UI Elements.

    How do I take care of this? My external email client is Lotus notes. Is it compatible for HTML Elements? or should I try using Outlook?

    Regards,
    Reema.

    (0) 
  12. Vimal Kumar
    Hi pavan,

      Nice weblog really useful.

    I have a problem,i’m getting the link text (the text that we give in smartform window text ) into my email and im not getting image in the body of the email. can u suggest what could be the problem.

    Thanks and regards,
    vimal

    (0) 
  13. neelima m
    Hi Pavan,
    Thanks for the blog. it helped a lot. but i am facing one problem during forwarding or replying to the HTML mail. When i try to forward the mail it does not move the mail body down. the body of the email remains fixed in the same location and if i type text it is hidden behind the original email body. please suggest.

    thanks

    (0) 
  14. muhamad husin
    Hi Pavan,

    Thanks for your useful blog, it really helpful for the beginner like me.

    I successfully testing the program, but having some difficulty on displaying the targeted URL image and URL link itself. I managed (successfully) to post the form to external mail, but the contains – it’s only a plain text without containing any html coding, that i put inside the smartforms. Can you give me any solution for this?

    Thanks and Regards,
    Muhamad.

    (0) 
    1. muhamad husin
      Hi Pavan,

      Thank you so much for sharing this useful this knowledge with me.

      I managed to do the URL Link thingy now. If anyone having the same problem as me, you can re-check back the HTML string part and make sure that you modified the string correctly there.

      Regards here.

      (0) 
  15. Anonymous
    Hi Pavan,
    We implemented your email solution with a PDF-attachment successfully in CRM. However now we get our content for the PDF-attachement not from a plain-text editor but from a BTF-editor in CRM. This text contains lots of HTML-tags, which are visible now in the content-Smartforms OTF-output and thus in the PDF attachment as well.
    What we want is nicely formatted text in our PDF, just like the BTF-editor. Do you have any solution for this?
    (0) 
      1. Abdul Shukoor Mohammed
        Hi,

        I am also facing the same problem. Did you reach the requirement how to convert html data in BTF editor to PDF format. Please reply if you had done this….

        Regards,
        Mohammed Shukoor.

        (0) 
  16. Badari Narayana Ta
    Pavan,

       Thanks for your blog. I am able to send the smart form in html format with images.

    In my requirement, if i click on the image, it should direct to another link.

    Can you please suggest me ?

    Regards
    Badari

    (0) 
  17. Lakshmi Soujanya
    Hi Pavan,
    Thank you so much for your blog. I used the same code for sending mail in HTML format. But the problem is i am getting horizantal and vertical scroll bars if the mail content exceeds more than a page.Could you please tell me how to delete those scroll bars?

    Regards,
    Lakshmi.Y

    (0) 
  18. C. Lighting
    Hi PAvan,
    this blog is realy good and almost solved my problem. But almost.

    The mail that is generated contains XHTML. ANd MS outlook does not support XHTML anymore. (Header in mail in outlook contains

    Do you think this is still teh solution for sending HTML e-mails from smartforms or would you advise another solution?

    Regards,

    Bas Heikens

    (0) 
  19. Durga Prasad
    Hi Pavan,

    First I want to say thanks for your Blog,
    While sending mails to Outlook 2007  it is working fine.
    But while sending mails like Gmail and Yahoo
    I struck up with some formatting issues .
    Could you tell me what would be the reason.

    (0) 
  20. anurag khanna

    Hi Guys,

    Thanks for sharing the above information. I have used the similar logic. However, I’m unable to understand 1 thing as described below and need your urgent help
    If I see the code as written by Pavan:

    REPLACE ALL OCCURRENCES OF ‘‘ IN HTML_STR WITH ‘/>’ IGNORING CASE.

    If you could see, there is something as . Guys can you please let me know what does it corresponds to. Does it correspond to “<img/>”?
    Those of you, who have implemented the code can help me out. I request the persons who know the solution to please respond as soon as possible…

    Thanks and Best Regards

    Anurag Khanna

    (0) 
    1. praveen kumar mannala

      we have already implemented this functionality. email format is fine in SCOT transaction. but when it reaches the outlook or gmail , format is totally changed and disturbed.

      any idea. kindly respond if any body faced or solved this problem.

      (0) 
  21. anurag khanna

    Hi Praveen,

    Good Day!!

    If you are also using Images in your email and if they are printing correctly, I request you to please share your code.
    The code which I have implemented is also working fine, but for printing the images, we have to write the code, as written by Pavan:

    Line1 : REPLACE ALL OCCURRENCES OF ‘‘ IN HTML_STR WITH ‘/>’ IGNORING CASE.

    Line2 : REPLACE ALL OCCURRENCES OF IN html_str WITH IGNORING CASE. “#EC NOTEXT
    Line 3: REPLACE ALL OCCURRENCES OF ‘<‘ IN html_str WITH ‘<‘ IGNORING CASE. “#EC NOTEXT
    Line 4:

    REPLACE ALL OCCURRENCES OF ‘>’ IN html_str WITH ‘>’ IGNORING CASE. “#EC NOTEXT

    a. Here could you please tell what corresponds to

    b. If I implment the above four lines of code also, by assuming as “<img/>”, then at line no. 2, the code gets dumps

    Please can you share the above 4 lines of code/reference code you have used…

    Thanks and Best Regards

    Anurag Khanna

    (0) 
  22. anurag khanna

    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

    (0) 

Leave a Reply