Skip to Content

image not displayed in outlook email when triggered via ABAP code

Dear Experts,

I have a requirement where I have to generate email for plant maintenance notification, In the email body (content) i need to display an image(jpeg) .

I have written the code as specified in the blog

Email is getting triggered however image is not displayed.

I have debugged my code and there is no issue. even the HTML source code from outlook email is also same as coded.

What else could be wrong? Please help as this is urgent.

See the attached image for more details.

My code snippet is as below

"Get image from mime repository in form of xstring

lr_mime_rep = cl_mime_repository_api=>if_mr_api~get_api( ).

CALL METHOD lr_mime_rep->get


i_url = '/SAP/PUBLIC/PM/notify.jpg'


e_is_folder = lv_folder

e_content = lv_content

e_loio = lv_loio


parameter_missing = 1

error_occured = 2

not_found = 3

permission_failure = 4

others = 5


IF sy-subrc <> 0.

* Implement suitable error handling here


"Convert the image from xstring to table form

call method cl_bcs_convert=>xstring_to_solix


iv_xstring = lv_content


et_solix = i_solix.

lv_len = xstrlen( lv_content ).

"Attach Image in xstring

lv_filename = 'PM/notify.jpg'.

lv_content_id = 'PM/notify.jpg'.

CREATE OBJECT lo_mime_helper.

CALL METHOD lo_mime_helper->add_binary_part


content = i_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_len "length of image

content_id = lv_content_id. "content id would be used in html part

* Prepare email body



INTO lv_line1.


'<img src="cid:PM/notify.jpg" width="668" height="191" />'

------ Skipping some lines of code

CALL METHOD cl_document_bcs=>create_document


i_text = lt_mail_body

i_subject = lv_subject

i_type = 'HTM'

i_language = sy-langu


result = lr_document.

Thanks & Regards


emailimg.jpg (15.0 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Jan 12, 2018 at 01:08 PM

    Check the html source for the <img src=cid:filename.jpg> tag, look at the attachment(s) of the mail, is the picture attached, does it use the same filename, are you able to download the attached image and display it?

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 12, 2018 at 02:10 PM

    It amazes me when I see code like this and people wonder why it doesn't work

    IF sy-subrc <> 0.
    * Implement suitable error handling here
    Add comment
    10|10000 characters needed characters exceeded

    • If you had read my response fully, you would have found that it was not proposing that this is the cause of your problem, but an observation on code quality. Code quality from the start is a very important part of solutions with fewer errors. "I will add error handling later" is something many developers say/think/hope, but sadly the majority of such code stays as is.