2020 Jul 16 9:17 AM
Hi All,
I am trying to print Logo in Outlook. I am using below code . but it's not working.Any correction required please help us.
DATA: lo_mr_api TYPE REF TO if_mr_api, "“mime repository object
lo_mime_helper TYPE REF TO cl_gbt_multirelated_service."Class for
DATA: lv_content TYPE xstring, "“image in XSTRING
lv_folder TYPE boole_d,
lv_loio TYPE skwf_io,
lv_obj_len TYPE so_obj_len,
lv_graphic_length TYPE tdlength,
lv_xstr TYPE xstring,
lv_offset TYPE i,
lv_length TYPE i,
lv_diff TYPE i,
**Attach image to HTML body
lv_filename TYPE string,
lv_content_id TYPE string.
DATA: lt_solix TYPE solix_tab,
lwa_solix TYPE solix.
DATA: l_bcs TYPE REF TO cl_bcs, " Send request
l_body TYPE bcsy_text, " Mail body
ls_body TYPE soli,
l_doc_bcs TYPE REF TO cl_document_bcs, " Mail body
l_sender TYPE REF TO if_sender_bcs, " Sender address
l_recipient TYPE REF TO if_recipient_bcs, " Recipient
i_subject TYPE so_obj_des."Subject
lo_mr_api = cl_mime_repository_api=>if_mr_api~get_api( ).
CALL METHOD lo_mr_api->get
EXPORTING
i_url = '/SAP/PUBLIC/AES/SAP Sailing.jpg'
IMPORTING
e_is_folder = lv_folder
e_content = lv_content
e_loio = lv_loio
EXCEPTIONS
parameter_missing = 1
error_occured = 2
not_found = 3
permission_failure = 4
OTHERS = 5.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
"Convert the image from xstring to table form
CALL METHOD cl_bcs_convert=>xstring_to_solix
EXPORTING
iv_xstring = lv_content
RECEIVING
et_solix = lt_solix.
lv_obj_len = XSTRLEN( lv_content ).
"Attach Image in xstring
lv_filename = 'SAP Sailing.jpg'.
lv_content_id = 'SAP Sailing.jpg'.
CREATE OBJECT lo_mime_helper.
CALL METHOD lo_mime_helper->add_binary_part
EXPORTING
content = lt_solix "Xstring in table form
filename = lv_filename "file name to be given to image
extension = 'JPG' "type of file
description = 'notify' "description
content_type = 'IMAGE/jpg' "content type / Mime type. If mime type not present in system
length = lv_obj_len "length of image
content_id = lv_content_id. "content id would be used in html part
* Prepare email body
*CONCATENATE '<html>'
*
*'<body>'
*
*INTO ls_body.
*
*APPEND ls_body TO l_body.
*CLEAR ls_body.
CONCATENATE '<br>'
'<img alt="[image]" src="cid:SAP Sailing.jpg" />'
*'<img src="cid:SAP Sailing.jpg" width="70" height="70" />'
'<br>' INTO ls_body.
CONDENSE ls_body NO-GAPS.
APPEND ls_body TO l_body.
CLEAR ls_body.
l_bcs = cl_bcs=>create_persistent( ).
*------ Skipping some lines of code
CLEAR i_subject.
CONCATENATE 'New PO' 'Test' INTO
i_subject SEPARATED BY ' '.
CALL METHOD cl_document_bcs=>create_document
EXPORTING
i_text = l_body
i_subject = i_subject
i_type = 'HTM'
i_language = sy-langu
RECEIVING
result = l_doc_bcs.
data : t_hexa TYPE solix_tab..
CALL METHOD l_doc_bcs->add_attachment
EXPORTING
i_attachment_type = 'PDF'
i_attachment_subject = i_subject
i_att_content_hex = t_hexa.
*Add the document to send request
CALL METHOD l_bcs->set_document( l_doc_bcs ).
*Sender addess
l_sender = cl_sapuser_bcs=>create( sy-uname ).
CALL METHOD l_bcs->set_sender
EXPORTING
i_sender = l_sender.
l_recipient = cl_cam_address_bcs=>create_internet_address( 'mahesh.kesireddy@xyz.com' ).
*Add recipient address to send request
CALL METHOD l_bcs->add_recipient
EXPORTING
i_recipient = l_recipient
i_express = 'X'
i_copy = ' '
i_blind_copy = ' '
i_no_forward = ' '.
*Trigger E-Mail immediately
l_bcs->set_send_immediately( 'X' ).
*Send mail
DATA: lv_sent_to_all(1) TYPE c VALUE IS INITIAL.
l_bcs->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = lv_sent_to_all ).
COMMIT WORK.
Thanks & Regards,
Mahesh K
2020 Jul 16 9:25 AM
here an old blog about oo mail & picture / attachment
https://blogs.sap.com/2013/05/30/sending-mail-using-oo-2-smartforms/
2020 Jul 16 9:50 AM
Hello mahesh.k15
I'd advise to format your question using the "Code" button for the ABAP part of your question.
As to your code, you have your image's CID as "SAP Sailing.jpg" with space. Then, you're using the CONDENSE on the body.
'<img alt="[image]" src="cid:SAP Sailing.jpg" />'
*'<img src="cid:SAP Sailing.jpg" width="70" height="70" />'
'<br>' INTO ls_body.
CONDENSE ls_body NO-GAPS.
In my opinion after condense your image's CID is "SAPSailing.jpg" hence the image with id "SAP Sailing.jpg" is not attached. I would suggest to avoid spaces in the CIDs. Maybe replace them with an underscore (_)?
Kind regards,
Mateusz2020 Jul 16 11:31 AM
Hello Mateusz Adamus,
Thanks for your prompt reply..
I was change image. Please find below code & output.
CONCATENATE '<br>'
'<img alt="[image]" src="cid:TF_Logo.jpg" />'
*'<img src="cid:SAP Sailing.jpg" width="70" height="70" />'
'<br>' INTO ls_body.
*CONDENSE ls_body NO-GAPS.
APPEND ls_body TO l_body.
CLEAR ls_body.
Output :
Thanks & Regards,
Mahesh K
2020 Jul 16 11:36 AM
Hello mahesh.k15
I don't see the output. Should there be an image attached?
Did you change the image's CID in the ADD_BINARY_PART method, too? Did the change work? Is the issue solved?
Kind regards,2020 Jul 16 11:47 AM
Hello Mateusz Adamus,
Please below link.
Did you change the image's CID in the ADD_BINARY_PART method, too?
Yes, It's changed .
CALL METHOD lo_mime_helper->add_binary_part
EXPORTING
content = lt_solix "Xstring in table form
filename = lv_filename "file name to be given to image
extension = 'JPG' "type of file
description = 'notify' "description
content_type = 'IMAGE/jpg' "content type / Mime type. If mime type not present in system
length = lv_obj_len "length of image
content_id = lv_content_id. "content id would be used in html part
Did the change work? Is the issue solved?
It's not solved . Please find attached output.
Thanks & Regards,
Mahesh K
2020 Jul 16 11:51 AM
this pics means the html code of your email did not find the picture file.
remove the 'cid:'
'<img alt="[image]" src="cid:SAP Sailing.jpg" />'
(edit your html code, you will see where the code would like to find the pics)
2020 Jul 16 12:02 PM
Hello MAHESH K
Please use the "Code" button to format your ABAP logic.
I do not see the LV_CONTENT_ID value, what is it? The code should be something like this.
lv_content_id = 'SAP_Sailing.jpg'.
CREATE OBJECT lo_mime_helper.
CALL METHOD lo_mime_helper->add_binary_part
EXPORTING
content = lt_solix "Xstring in table form
filename = lv_filename "file name to be given to image
extension = 'JPG' "type of file
description = 'notify' "description
content_type = 'IMAGE/jpg' "content type / Mime type. If mime type not present in system
length = lv_obj_len "length of image
content_id = lv_content_id. "content id would be used in html part
* Prepare email body
CLEAR ls_body.
CONCATENATE '<br>' '<img alt="[image]" src="cid:SAP_Sailing.jpg" />' '<br>' INTO ls_body.
APPEND ls_body TO l_body.
CLEAR ls_body.
After you've sent your email, please save it to your PC and check if it contains the image in the body of it (via Notepad, for example). I have not used the ADD_BINARY_PART before and am not sure if it attaches the image correctly.
@Frederic Girod CID is required, that's how HTML emails find images in the body of the email.
2020 Jul 27 9:27 AM
Hi All,
This issue is solved. Thanks for your response.
It's 120 lines of code for logo display in outlook. Instead of 120 lines code is there any possibilities by using Logo Web link HTML code in SAP ABAP.
Thanks & Regards,
Mahesh K
2024 Nov 07 9:03 AM
Hi Mahesh K,
could you please send your final code..
Thanks,
Kavitha G.