E-Mail formatting using Standard Texts made simplified

As a utility firm, we are engaged in sending mails to many a customers and vendors of various aspects, and details. Some mails are with extensive graphics and URL links, and some are simple, with attachments. There have been many instances, fellow folks were struggling in formatting the mail body. Reading the content from Text elements, Standard texts, and adopting with huge formatting.

Using the standard texts (SO10) for storing the mail body is not a new concept, But when we get the standard Text thru READ_TEXT function module, the later falls a hectic part in formatting the mail to the desired output.

Yet, the advantage is, SO10 comes with the option of uploading the text with ‘.rtf’  Rich Text files.

Below are three standard texts. This will preserve the mail body, and appears with similar format of that of the uploaded file ‘.rtf’ in SO10.

Frame Work Adapted

  • Created three standard texts for header, footer and body.
  • The Header and footer standard texts can be used for complex HTML design formatting.
  • The body standard text is used to send mail body of intended scenario.
  • All texts are appended to an internal table, and sent to a utility class for formatting to CL_BCS_SEND mail content format.
  • Function modules READ_TEXT and CONVERT_ITF_TO_STREAM_TEXT is used to convert the standard text to required format.
  • The returned internal table ‘RT_MAIL_BODY’ is now a formatted mail content of HTML type derived form standard texts.

The main body texts, which can be changed dynamically based on the scenario.

The Header and footer above can be replaced by complex HTML formatting to send the mails to Customers / Vendors with brand image and extensive URL Links. This will ensure the centralized maintenance of mail formatting and secure source for the HTML source data.

Advantages : No additional mail formatting is necessary while drafting mail data.

Below snap shot shows the e-mail source code that was adapted.

Here, all the standard texts as in above snap shots are appended to a internal table, and passed to a utility class to get the mail body required.

TRY.
CLEAR lt_thead.
lv_thead-tdobject = TEXT.
lv_thead-tdname = Z***_HTML_HEADER.
lv_thead-tdid = ST.
lv_thead-tdspras = sy-langu.
APPEND lv_thead TO lt_thead.
CLEAR lv_thead.
lv_thead-tdobject = TEXT.
lv_thead-tdname = lv_mailbody.
lv_thead-tdid = ST.
lv_thead-tdspras = sy-langu.
APPEND lv_thead TO lt_thead.
CLEAR lv_thead.
lv_thead-tdobject = TEXT.
lv_thead-tdname = Z***_HTML_FOOTER.
lv_thead-tdid = ST.
lv_thead-tdspras = sy-langu.
APPEND lv_thead TO lt_thead.
CLEAR lv_thead.
*
CALL METHOD cl_sd_util>build_mail_body_from_itf
EXPORTING
im_thead  = lt_thead
RECEIVING
rt_content_txt = rt_mail_body.
************

Reading the standard text, and converting to ‘BUBAS_T_MAIL_CONTENT’ Table with Mail Content format .

METHOD build_mail_body_from_itf.
*
DATA : lt_lines TYPE STANDARD TABLE OF tline,
lt_lines_final TYPE STANDARD TABLE OF tline,
lv_string TYPE string_table,
ls_thead TYPE thead.
*
LOOP AT im_thead INTO ls_thead.
*
CALL FUNCTION READ_TEXT
EXPORTING
*  CLIENT = SY-MANDT
id  = ls_thead-tdid
language  = ls_thead-tdspras
name  = ls_thead-tdname
object  = ls_thead-tdobject
TABLES
lines  = lt_lines
EXCEPTIONS
id  = 1
language  = 2
name  = 3
not_found  = 4
object  = 5
reference_check  = 6
wrong_access_to_archive = 7
OTHERS  = 8.
IF sy-subrc EQ 0.
APPEND LINES OF lt_lines TO lt_lines_final.
CLEAR lt_lines.
ELSE.
RAISE EXCEPTION TYPE zcx_exc_class_wdobjectsk
EXPORTING
textid = zcx_exc_class_wdobjectsk=>zcx_nodatadata.
ENDIF.
*
ENDLOOP.
IF sy-subrc EQ 0.
*
CALL FUNCTION CONVERT_ITF_TO_STREAM_TEXT
EXPORTING
language  = sy-langu
lf  =
IMPORTING
stream_lines = lv_string
TABLES
itf_text  = lt_lines_final
text_stream  = rt_content_txt[].
ELSE.
RAISE EXCEPTION TYPE zcx_exc_class_wdobjectsk
EXPORTING
textid = zcx_exc_class_wdobjectsk=>zcx_nodatadata.
ENDIF.
ENDMETHOD.

The method returns RT_MAIL_BODY of type BUBAS_T_MAIL_CONTENT, which can be exported to  cl_document_bcs to send the mail in HTML format.

  document = cl_document_bcs=>create_document(
i_type  = HTM
i_text  = RT_MAIL_BODY[]
i_importance = 1  changes to make priority low
i_length  = lv_size
i_subject = document_data-obj_descr ).

 

 

Mail received in HTML Format.

 



As a result, Many a complex scenarios with extensive HTML designs can be sent as e-mails with varied body context. The single framework can be adopted with various contexts to suit the scenario.

 

Tried and tested below generated customer notification mail with the above frame work. For illustration.

 

 

Please comment, reply for any suggestions and alterations to the post.

 

Thanks.

New NetWeaver Information at SAP.com

Very Helpfull

 

 

User Rating: Be the first one !

Comments (0)
Add Comment