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

https://blogs.sap.com/2013/06/11/image-in-mail-body-in-abap/

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

EXPORTING

i_url = '/SAP/PUBLIC/PM/notify.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 = 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

EXPORTING

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

CONCATENATE '<html>'

'<body>'

INTO lv_line1.

CONCATENATE '<p>'

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

------ Skipping some lines of code

CALL METHOD cl_document_bcs=>create_document

EXPORTING

i_text = lt_mail_body

i_subject = lv_subject

i_type = 'HTM'

i_language = sy-langu

RECEIVING

result = lr_document.

Thanks & Regards

Gopal

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

  • Get RSS Feed

2 Answers

  • Best Answer
    Jan 12 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 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
    ENDIF.
    Add comment
    10|10000 characters needed characters exceeded

    • Mike Pokraka Gopalkrishna Baliga

      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.