Tuesday, November 6, 2012
The following are the simple steps.
- Create one standard text at SO10 transaction code. e.g. ZTST_VKO.
- Text with HTML code.
- Create one program at SE38. e.g. zvko_simple_html_mail
- Program code.
<html> <head> </head> <body> <p>Hello friends</p> <P>This program demonstrates on how to send mail with HTML body. You can use HTML tags.</p> <p><font color=red> This is in red color</font></p> <p><font size=5> This font size is big</font></p> <p>Thank You</p> </body> </html>
- Mail in HTML format.
REPORT zvko_simple_html_mail. *&-------------------------------------------------------------------* "Declaration *&-------------------------------------------------------------------* "Variables DATA : g_sent_to_all TYPE sonv-flag, g_tab_lines TYPE i. "Types TYPES: t_document_data TYPE sodocchgi1, t_packing_list TYPE sopcklsti1, t_attachment TYPE solisti1, t_body_msg TYPE solisti1, t_receivers TYPE somlreci1. "Workareas DATA : w_document_data TYPE t_document_data, w_packing_list TYPE t_packing_list, w_attachment TYPE t_attachment, w_body_msg TYPE t_body_msg, w_receivers TYPE t_receivers. "Internal Tables DATA : i_document_data TYPE STANDARD TABLE OF t_document_data, i_packing_list TYPE STANDARD TABLE OF t_packing_list, i_attachment TYPE STANDARD TABLE OF t_attachment, i_body_msg TYPE STANDARD TABLE OF t_body_msg, i_receivers TYPE STANDARD TABLE OF t_receivers. DATA: lt_datatab TYPE tdtab_c132, lw_data LIKE LINE OF lt_datatab. DATA :i_body TYPE STANDARD TABLE OF tline WITH HEADER LINE. *&-------------------------------------------------------------------* "Selection Screen *&-------------------------------------------------------------------* PARAMETERS:p_mail TYPE char120. *&-------------------------------------------------------------------* "Start-of-selection *&-------------------------------------------------------------------* START-OF-SELECTION. "Subject of the mail. w_document_data-obj_name = 'MAIL_TO_HEAD'. w_document_data-obj_descr = 'SAP ABAP - Mail in HTML format'. "Body of the mail CALL FUNCTION 'READ_TEXT' EXPORTING client = sy-mandt id = 'ST' language = sy-langu name = 'ZTST_VKO' object = 'TEXT' TABLES lines = i_body[]. CALL FUNCTION 'CONVERT_ITF_TO_ASCII' EXPORTING language = sy-langu tabletype = 'ASC' IMPORTING c_datatab = lt_datatab TABLES itf_lines = i_body[]. CLEAR i_body[]. LOOP AT lt_datatab INTO lw_data. w_body_msg-line = lw_data. APPEND w_body_msg TO i_body_msg. CLEAR w_body_msg. ENDLOOP. "Write Packing List (Body) DESCRIBE TABLE i_body_msg LINES g_tab_lines. w_packing_list-head_start = 1. w_packing_list-head_num = 0. w_packing_list-body_start = 1. w_packing_list-body_num = g_tab_lines. w_packing_list-doc_type = 'HTM'. APPEND w_packing_list TO i_packing_list. CLEAR w_packing_list. "Fill the document data and get size of attachment READ TABLE i_body_msg INTO w_body_msg INDEX g_tab_lines. w_document_data-doc_size = ( g_tab_lines - 1 ) * 255 + strlen( w_body_msg ). "Receivers List. w_receivers-rec_type = 'U'. "Internet address w_receivers-receiver = p_mail. w_receivers-com_type = 'INT'. w_receivers-notif_del = 'X'. w_receivers-notif_ndel = 'X'. APPEND w_receivers TO i_receivers . CLEAR:w_receivers. "Function module to send mail to Recipients CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' EXPORTING document_data = w_document_data put_in_outbox = 'X' commit_work = 'X' IMPORTING sent_to_all = g_sent_to_all TABLES packing_list = i_packing_list contents_txt = i_body_msg receivers = i_receivers EXCEPTIONS too_many_receivers = 1 document_not_sent = 2 document_type_not_exist = 3 operation_no_authorization = 4 parameter_error = 5 x_error = 6 enqueue_error = 7 OTHERS = 8. IF sy-subrc = 0 . MESSAGE i303(me) WITH 'Mail has been Successfully Sent.'. ELSE. WAIT UP TO 2 SECONDS. SUBMIT rsconn01 WITH mode = 'INT' WITH output = 'X' AND RETURN. ENDIF.
Followers
Popular Posts
- ABAP - ALV Report example with steps
- ABAP - Step by step tutorial on Smart Forms - Template Node
- ABAP - Sending email with pdf attachment
- SAP Adobe Form - Steps to create simple ADOBE Form and calling it from ABAP Program
- SAP ABAP - CL_ABAP_CHAR_UTILITIES class usage
- ABAP - Multiple value selection from F4 help for SELECT-OPTIONS
- Execute ABAP Report using SUBMIT statement
- ABAP - Select all or Deselect all in ALV or Check box handling in ALV
- Web Dynpro ABAP ALV - ON_CLICK event
- ABAP - Dynamic WHERE clause
Excellent and thanks a lot , 1 thing , can you put an image as background ? , i mean to work the mail just like that but to be able to put an image in the background to be more presentable to a client
ReplyDelete