Skip to Content
0

image not displayed in outlook email when triggered via ABAP code

Jan 12 at 12:41 PM

104

avatar image

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)
10 |10000 characters needed characters left characters exceeded

It would help if you display the entire message. It would also help if you shared your actual code. Otherwise, we can't help.

Michelle

0

Please format your code, it's difficult to read it. There's a button "CODE".

0
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Raymond Giuseppi
Jan 12 at 01:08 PM
1

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?

Show 6 Share
10 |10000 characters needed characters left characters exceeded

Hi Raymond

I have checked the HTML source and it is fine. image is not coming as attachment. I cannot download the image as well. i have updated my text above with more details like code snippets. See above.

Thanks

Gopal

0
Gopalkrishna Baliga

So correct the code that send the mail to attach the image file.

Hint: Look for the add_binary_part method in original blog.

0

In your first comment you asked me to check if there is any attachment in the email.

And my answer is "No".

I am also not expecting any attachment.

I want image in email body. The code I have written is correct but still image is not displayed in the email output.

Hope you are getting my question.

Thanks

Gopal

0
Gopalkrishna Baliga

If your html code contains a cif: tag your mail must carry an attachment, I was expecting one (else why would I ask you to download and display it?) ;-)

Hint: Seems you created wrongly the document, use cl_document_bcs=>create_from_multirelated (as in the original blog) and not cl_document_bcs=>create_document which doesn't add the attachment.

1

So you are saying that even if I just want the image to be embedded in the email body I have to use cl_document_bcs=>create_from_multirelated?

Anyway I try that too.

0

Yes this worked.

Thanks A lot!

Regards

Gopal

0
Mike Pokraka Jan 12 at 02:10 PM
1

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.
Show 2 Share
10 |10000 characters needed characters left characters exceeded

Dear Sir,

If you have read my question fully then You will find that i have clearly mentioned that I have done the debugging and there is no error. So its not even going to any exception block. To be more clear sy-subrc is always 0.

Moreover please understand that this is not a final code that I can share. Once i get the basic functionality up and working then i will add all the exception/error handling.

Regards

Gopal

0
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.

1