2021 May 28 6:27 AM
Hi,
To display Images on the Email .
I have followed all steps to display the images on the email, still it is showing blank image when received the email, Request you to have a look and advice. Note that i have used correct image file source name , it is maintained in mime repository.
Email is working, however no image.
Here is the code :
REPORT zrich_0002.DATA: maildata LIKE sodocchgi1.
DATA: mailtxt LIKE solisti1OCCURS 10 WITH HEADER LINE.
DATA: mailrec LIKE somlrec90 OCCURS 0 WITH HEADER LINE.
PARAMETERS: p_email type ad_smtpadr.
DATA: o_mr_api TYPE REF TO if_mr_api.
DATA: v_str TYPE string,
wa_reclist TYPE somlreci1,
gt_reclist TYPE STANDARD TABLE OF somlreci1,
wa_docdata TYPE sodocchgi1,
wa_objpack TYPE sopcklsti1,
gt_objpack TYPE STANDARD TABLE OF sopcklsti1,
wa_objtxt TYPE solisti1,
gt_objtxt TYPE STANDARD TABLE OF solisti1,
gs_objtxt TYPE solisti1,
gt_objbin TYPE STANDARD TABLE OF solisti1,
wa_objbin TYPE solisti1,
iv_id TYPE thead-tdid VALUE 'ST',
iv_langu TYPE thead-tdspras VALUE 'E',
iv_object TYPE thead-tdobject VALUE 'TEXT',
iv_name TYPE thead-tdname,
lt_lines TYPE idmx_di_t_tline,
ls_lines TYPE tline,
lt_soli TYPE soli_tab,
ls_soli TYPE soli,
lt_solix TYPE solix_tab,
ls_solix TYPE solix,
lv_string TYPE string,
lv_total_lines(3) TYPE i,
ls_head TYPE thead,
lv_quote TYPE char1 VALUE ' '
.DATA is_folder TYPE boole_d.DATA gv_content TYPE xstring.
DATA :l_loio TYPE skwf_io,
lv_length TYPE i,
lv_len TYPE i,
lt_img_data TYPE string,
o_mime_helper TYPE REF TO cl_gbt_multirelated_service,
LT_DATA type standard table of x255,* lv_string TYPE string,
lv_xstring TYPE xstring,
l_filename TYPE string,
l_content_id TYPE string,
l_obj_len TYPE so_obj_len,
lv_len3 TYPE i,
temp1 TYPE i,
temp2 TYPE i,
lv_obj_len TYPE so_obj_len,
lv_graphic_len TYPE tdlength,
gr_xstr TYPE xstring,
l_offset TYPE i,
lv_diff TYPE i,
l_length TYPE i.START-OF-SELECTION.
CLEAR: maildata, mailtxt,mailrec.REFRESH: mailtxt, mailrec.
PERFORM build_text_message.perform send_mail_new.
****Form BUILD_TEXT_MESSAGE************************************************************************
FORM build_text_message.
maildata-obj_name = 'TEST'.
maildata-obj_descr = 'Test Subject'.
ls_soli-line = '<html>'.APPEND ls_soli TO lt_soli.
ls_soli-line = '<head>'.APPEND ls_soli TO lt_soli.
ls_soli-line = '<title>Untitled Document</title>'.APPEND ls_soli TO lt_soli.
ls_soli-line = '<meta http-equiv="Content-Type" content="text/html;'.APPEND ls_soli TO lt_soli.
ls_soli-line = 'charset=iso-8859-1">'.APPEND ls_soli TO lt_soli.
ls_soli-line = '</head>'.APPEND ls_soli TO lt_soli.
ls_soli-line = '<body>'.APPEND ls_soli TO lt_soli.
ls_soli-line = '<em><font'.APPEND ls_soli
PERFORM upload_image.
ls_soli-line = '</body>'.APPEND ls_soli TO lt_soli.
ls_soli-line = '</html>'.APPEND ls_soli TO lt_soli.
ENDFORM.*************************************************************************
*& Form UPLOAD_IMAGE*&--------------------------------------------------------------------
*FORM upload_image .
IF o_mr_api IS INITIAL.
o_mr_api = cl_mime_repository_api=>if_mr_api~get_api( ).ENDIF.
CALL METHOD o_mr_api->getEXPORTING
i_url = '/SAP/PUBLIC/ZLOGO.JPG' "Customer_notification1.PNG'IMPORTING
e_is_folder = is_folder
e_content = gv_content
e_loio = l_loioEXCEPTIONS
parameter_missing = 1
error_occured = 2
not_found = 3
permission_failure = 4OTHERS = 5.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'EXPORTINGbuffer = gv_contenttables
binary_tab = LT_DATA.
lv_obj_len = xstrlen( gv_content ) .
lv_graphic_len = xstrlen( gv_content ).CLEAR gr_xstr.
gr_xstr = gv_content(lv_obj_len).
l_offset = 0 .
l_length = 255.
CLEAR lt_solix[].
WHILE l_offset < lv_graphic_len.
lv_diff = lv_graphic_len - l_offset.IF lv_diff > lv_length.
ls_solix-line = gr_xstr+l_offset(lv_length).
ELSE.
ls_solix-line = gr_xstr+l_offset(lv_diff).ENDIF.
APPEND ls_solix TO lt_solix.ADD l_length TO l_offset.ENDWHILE.
l_filename = 'Cust_Note.png'.
l_content_id = 'Cust_Note.png'.
CREATE OBJECT o_mime_helper.
CALL METHOD o_mime_helper->add_binary_part
EXPORTING
content = lt_solix " Objcont and Objhead as Table Type
filename = l_filename " File Name (Proposal Only)
extension = 'png' " File extension for PC application
description = 'Graphic in PNG format' " Short description of contents
content_type = 'image/png' " HTML content type
length = lv_obj_len " Size of Document Content
content_id = l_content_id. " BCOM: Bodypart Content ID
CONCATENATE '<BR>' '<img alt="[image]"src="[email protected]’.
lo_recipient = cl_cam_address_bcs=>create_internet_address( i_address_string = lv_receiver ).
lo_bcs->add_recipient( i_recipient = lo_recipient ).*Set sender
lo_sender = cl_sapuser_bcs=>create( lv_senderid ).
lo_bcs->set_sender( i_sender = lo_sender ).
lo_bcs->set_send_immediately( i_send_immediately = abap_true ).
lo_bcs->send( ).
commit work and wait.
catch cx_bcs into lv_bcs_exception.endtry.clear: lo_bcs, lv_receiver, lo_sender.
ENDFORM.
Hi,
To display Images on the Email .
I have followed all steps to display the images on the email, still it is showing blank image when received the email, Request you to have a look and advice. Note that i have used correct image file source name , it is maintained in mime repository.
Email is working, however no image.
Here is the code :
REPORT zrich_0002.DATA: maildata LIKE sodocchgi1.
DATA: mailtxt LIKE solisti1OCCURS 10 WITH HEADER LINE.
DATA: mailrec LIKE somlrec90 OCCURS 0 WITH HEADER LINE.
PARAMETERS: p_email type ad_smtpadr.
DATA: o_mr_api TYPE REF TO if_mr_api.
DATA: v_str TYPE string,
wa_reclist TYPE somlreci1,
gt_reclist TYPE STANDARD TABLE OF somlreci1,
wa_docdata TYPE sodocchgi1,
wa_objpack TYPE sopcklsti1,
gt_objpack TYPE STANDARD TABLE OF sopcklsti1,
wa_objtxt TYPE solisti1,
gt_objtxt TYPE STANDARD TABLE OF solisti1,
gs_objtxt TYPE solisti1,
gt_objbin TYPE STANDARD TABLE OF solisti1,
wa_objbin TYPE solisti1,
iv_id TYPE thead-tdid VALUE 'ST',
iv_langu TYPE thead-tdspras VALUE 'E',
iv_object TYPE thead-tdobject VALUE 'TEXT',
iv_name TYPE thead-tdname,
lt_lines TYPE idmx_di_t_tline,
ls_lines TYPE tline,
lt_soli TYPE soli_tab,
ls_soli TYPE soli,
lt_solix TYPE solix_tab,
ls_solix TYPE solix,
lv_string TYPE string,
lv_total_lines(3) TYPE i,
ls_head TYPE thead,
lv_quote TYPE char1 VALUE ' '
.DATA is_folder TYPE boole_d.DATA gv_content TYPE xstring.
DATA :l_loio TYPE skwf_io,
lv_length TYPE i,
lv_len TYPE i,
lt_img_data TYPE string,
o_mime_helper TYPE REF TO cl_gbt_multirelated_service,
LT_DATA type standard table of x255,* lv_string TYPE string,
lv_xstring TYPE xstring,
l_filename TYPE string,
l_content_id TYPE string,
l_obj_len TYPE so_obj_len,
lv_len3 TYPE i,
temp1 TYPE i,
temp2 TYPE i,
lv_obj_len TYPE so_obj_len,
lv_graphic_len TYPE tdlength,
gr_xstr TYPE xstring,
l_offset TYPE i,
lv_diff TYPE i,
l_length TYPE i.START-OF-SELECTION.
CLEAR: maildata, mailtxt,mailrec.REFRESH: mailtxt, mailrec.
PERFORM build_text_message.perform send_mail_new.
****Form BUILD_TEXT_MESSAGE************************************************************************
FORM build_text_message.
maildata-obj_name = 'TEST'.
maildata-obj_descr = 'Test Subject'.
ls_soli-line = '<html>'.APPEND ls_soli TO lt_soli.
ls_soli-line = '<head>'.APPEND ls_soli TO lt_soli.
ls_soli-line = '<title>Untitled Document</title>'.APPEND ls_soli TO lt_soli.
ls_soli-line = '<meta http-equiv="Content-Type" content="text/html;'.APPEND ls_soli TO lt_soli.
ls_soli-line = 'charset=iso-8859-1">'.APPEND ls_soli TO lt_soli.
ls_soli-line = '</head>'.APPEND ls_soli TO lt_soli.
ls_soli-line = '<body>'.APPEND ls_soli TO lt_soli.
ls_soli-line = '<em><font'.APPEND ls_soli
PERFORM upload_image.
ls_soli-line = '</body>'.APPEND ls_soli TO lt_soli.
ls_soli-line = '</html>'.APPEND ls_soli TO lt_soli.
ENDFORM.*************************************************************************
*& Form UPLOAD_IMAGE*&--------------------------------------------------------------------
*FORM upload_image .
IF o_mr_api IS INITIAL.
o_mr_api = cl_mime_repository_api=>if_mr_api~get_api( ).ENDIF.
CALL METHOD o_mr_api->getEXPORTING
i_url = '/SAP/PUBLIC/ZLOGO.JPG' "Customer_notification1.PNG'IMPORTING
e_is_folder = is_folder
e_content = gv_content
e_loio = l_loioEXCEPTIONS
parameter_missing = 1
error_occured = 2
not_found = 3
permission_failure = 4OTHERS = 5.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'EXPORTINGbuffer = gv_contenttables
binary_tab = LT_DATA.
lv_obj_len = xstrlen( gv_content ) .
lv_graphic_len = xstrlen( gv_content ).CLEAR gr_xstr.
gr_xstr = gv_content(lv_obj_len).
l_offset = 0 .
l_length = 255.
CLEAR lt_solix[].
WHILE l_offset < lv_graphic_len.
lv_diff = lv_graphic_len - l_offset.IF lv_diff > lv_length.
ls_solix-line = gr_xstr+l_offset(lv_length).
ELSE.
ls_solix-line = gr_xstr+l_offset(lv_diff).ENDIF.
APPEND ls_solix TO lt_solix.ADD l_length TO l_offset.ENDWHILE.
l_filename = 'Cust_Note.png'.
l_content_id = 'Cust_Note.png'.
CREATE OBJECT o_mime_helper.
CALL METHOD o_mime_helper->add_binary_part
EXPORTING
content = lt_solix " Objcont and Objhead as Table Type
filename = l_filename " File Name (Proposal Only)
extension = 'png' " File extension for PC application
description = 'Graphic in PNG format' " Short description of contents
content_type = 'image/png' " HTML content type
length = lv_obj_len " Size of Document Content
content_id = l_content_id. " BCOM: Bodypart Content ID
CONCATENATE '<BR>' '<img alt="[image]"src="[email protected]’.
lo_recipient = cl_cam_address_bcs=>create_internet_address( i_address_string = lv_receiver ).
lo_bcs->add_recipient( i_recipient = lo_recipient ).*Set sender
lo_sender = cl_sapuser_bcs=>create( lv_senderid ).
lo_bcs->set_sender( i_sender = lo_sender ).
lo_bcs->set_send_immediately( i_send_immediately = abap_true ).
lo_bcs->send( ).
commit work and wait.
catch cx_bcs into lv_bcs_exception.endtry.clear: lo_bcs, lv_receiver, lo_sender.
ENDFORM.
2021 May 28 6:39 AM
2021 May 28 6:44 AM
If you use the MIME Helper class to attach the image, where is:
lo_document_bcs = cl_document_bcs=>create_from_multirelated(
i_subject = 'my subject'
i_multirel_service = o_mime_helper ).
?
(+ methods set_main_text or set_main_html...)
2021 May 28 6:47 AM
sandra.rossi you take time to read all this raw code ? You are persistent ! 🙂
2021 May 28 7:39 AM
The code tag is your friend. sandra.rossi deserves a medal because she read your post entirely. frdric.girod should be used to post his comments as answers, because usually his comments answers are (as Master Yoda said).
2021 May 28 8:34 AM
Thanks Rossi,
I have already having all these statements.
* lv_filename = 'cusomter_notification1.htm'.
lv_filename = 'Cust_Note.png'.create object o_mime_helper.
call method o_mime_helper->set_main_htmlexporting
content = lt_soli
filename = lv_filename " filename for HMTL form
description = 'customer notification'. " Title'*"Create HTML using BCS class and attach html and image part to it.
l_subject = 'customer notification'.* endif.try.
lo_doc_bcs = cl_document_bcs=>create_from_multirelated(
i_subject = l_subject
i_multirel_service = o_mime_helper ).
catch cx_document_bcs into lv_document_bcs.catch cx_bcom_mime into lv_bcom_mime.catch cx_gbt_mime into lv_gbt_mime.endtry.
if lv_senderid is initial.
lv_senderid = sy-uname.endif.
endif.
please have a look and let me know if get any help, thanks in advance.
regards
Hari Yoga
2021 May 28 8:35 AM
vicen.lozano are you looking like Yoda ? 🙂
I used the comment when I help a little bit, but I do not provide a full solution.
2021 May 28 9:21 AM
I try actively to NOT provide a full solution if able. I tuly believe to give a hint is to teach to fish, and to give a full solution is to create a lazy leecher.
My code snipets are just samples what almost never work (even compile). Your comment was useful enough to allow the OP to reach the solution through it. And this is the kind of answer I crave when I post a question somewhere: a hint that leads me to the finish line, not a full working code I can copy and solve my problem without any understanding about why it works.
(and no, sadly I don't look like Yoda, I'm by far more ugly)
2021 May 28 9:34 AM
As "Stack Overflow Yoda" says: "please post a minimum reproducible example, and we can tell you what your error is 😉
Otherwise try all the examples in the Web, there will be a working code.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |