Hi all,
I am doing the customization for email notification using the badi 'BADI_BUILD_MESSAGE' for a specific client. I want to include client's logo in the alert notification email. I have used the following document http://scn.sap.com/docs/DOC-42618 and the code given to the same to attach the logo in the mail body. The logo is placed in the MIME repository under 'SAP/PUBLIC' folder.
Following is the code that i have included into custimised method for BADI_BUILD_MESSAGE.:
"Create image in xstring form
*For Mime Repository
DATA : gv_mr_api TYPE REF TO if_mr_api, "mime repository object
gv_content TYPE xstring, "image in XSTRING
is_folder TYPE boole_d,
l_loio TYPE skwf_io.
*Image to Xstring Table form
DATA : l_obj_len TYPE so_obj_len,
lv_graphic_length TYPE tdlength,
gr_xstr TYPE xstring,
l_offset TYPE i,
l_length TYPE i,
l_diff TYPE i,
ls_solix TYPE solix,
lt_solix TYPE solix_tab.
*Attach image to HTML body
DATA: l_filename TYPE string,
l_content_id TYPE string.
*Create image in xstring form
IF gv_mr_api IS INITIAL.
gv_mr_api = cl_mime_repository_api=>if_mr_api~get_api( ).
ENDIF.
CALL METHOD gv_mr_api->get
EXPORTING
i_url = '/SAP/PUBLIC/abcd.jpg' "Image path
IMPORTING
e_is_folder = is_folder
e_content = gv_content
e_loio = l_loio
EXCEPTIONS
parameter_missing = 1
error_occured = 2
not_found = 3
permission_failure = 4
OTHERS = 5.
*Convert Image to Xstring table form
l_obj_len = XSTRLEN( gv_content ).
lv_graphic_length = XSTRLEN( gv_content ).
"get whole image
CLEAR gr_xstr.
gr_xstr = gv_content(l_obj_len).
l_offset = 0.
l_length = 255.
CLEAR lt_solix[].
WHILE l_offset < lv_graphic_length.
l_diff = lv_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.
*Attach image to HTML body
l_filename = 'abcd.jpg'.
l_content_id = 'abcd.jpg'.
CREATE OBJECT lo_mime_helper.
CALL METHOD lo_mime_helper->add_binary_part
EXPORTING
content = lt_solix "Xstring in table form
filename = l_filename "file name to be given to image
extension = 'JPG' "type of file
description = 'Graphic in JPG format' "description
content_type = 'image/jpg' "content type / Mime type. If mime type not present in system then need to add through tcode : SMW0
length = l_obj_len "length of image
content_id = l_content_id. "content id would be used in html part
*Create HTML mail body Content
REFRESH lt_soli[].
CLEAR ls_soli.
ls_soli = '<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-template/2.1/"><head></head>'.
APPEND ls_soli TO lt_soli.
CLEAR ls_soli.
ls_soli = '<body>'.
APPEND ls_soli TO lt_soli.
"to apply font to HTML body content
"For displaying Image
CLEAR ls_soli.
ls_soli = '<br><img alt="No image" src="cid:abcd.jpg" /><br>'.
APPEND ls_soli TO lt_soli.
CLEAR ls_soli.
CONCATENATE '</body></html>' INTO ls_soli SEPARATED BY space.
APPEND ls_soli TO lt_soli.
I have ommited to call the object 'lo_mime_helper' as mentioned in the original code given at http://scn.sap.com/docs/DOC-42618 as the BADI_BUILD_MESSAGE automaticaly create the sender and reciver for the mail.
I am getting the mail with 'X' No image in IBM Lotus Notes. I dont know what is wrong with the code. Why this code does not show the icon in the email. Any help will be appreciated.
Thanks and Regards,
Rutvik Upadhyay