Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Outlook email with images in body not working on mobile

Former Member
0 Kudos
770

Hey abapers,

I am developing a program which sends mail from sap to an external internet address.In the email body i have images which are stored in mime repository. I am using API for mime repository to get the image and attaching it to the mail using add_attachment method of cl_document_bcs and to make it visible in the mail body i am using this HTML statement <img src="cid:<attachment_subject>.jpg">.

The outlook mail is appearing correctly on the pc but on mobile the images are appearing as attachments and on download images also its not sitting on the correct positons in the mail.

PC screen shot:


Mobile ouptut






Below is the code which i am using:


HTML:

<!DOCTYPE html>',

'<html>',

'<body style="background:white">',

'<table align="left" style=" width:40%;border: 200px solid rgb(220,220,220);">',

'<tr>',

'<td colspan = "2"><img src="cid:dh.jpg"></td>',

'</tr>',

'<tr>',

'<td colspan = "2"><img src="cid:wpic.jpg"></td>',

'</tr>',

'<tr style= " margin-top:25px;">'.

Getting image from mime repository (API for mime repository)


IF o_mr_api IS INITIAL.

   o_mr_api = cl_mime_repository_api=>if_mr_api~get_api( ).

ENDIF.

CALL METHOD o_mr_api->get

   EXPORTING

     i_url              = '/SAP/PUBLIC/UTSAV MAIL/DeloitteHeader.jpg'

   IMPORTING

     e_is_folder        = is_folder

     e_content          = l_img1

     e_loio             = l_loio

   EXCEPTIONS

     parameter_missing  = 1

     error_occured      = 2

     not_found          = 3

     permission_failure = 4

     OTHERS             = 5.



Attaching image to the mail


WHILE l_img1 IS NOT INITIAL.

   ls_hex-line = l_img1.

   APPEND ls_hex TO lt_hex1.

   SHIFT l_img1 LEFT BY 255 PLACES IN BYTE MODE.

ENDWHILE.

*Findthe Size of the image

DESCRIBE TABLE lt_hex1 LINES lv_img1_size.

lv_img1_size = lv_img1_size * 255.

*--------------------------------------------------------------------*

*Attach Images

*--------------------------------------------------------------------*

lo_document->add_attachment(

   EXPORTING

     i_attachment_type     'jpg'                  " Document Class for Attachment

     i_attachment_subject  'dh'                " Attachment Title

     i_attachment_size     lv_img1_size           " Size of Document Content

     i_att_content_hex     lt_hex1  " Content (Binary)

).

CLEAR: ls_hex,lv_img1_size.

REFRESH lt_hex1.


Sending mail


TRY.

     CALL METHOD lo_bcs->add_recipient

       EXPORTING

         i_recipient = lo_recipient

         i_express   = 'X'.

   CATCH cx_send_req_bcs.

ENDTRY.


lo_sender = cl_cam_address_bcs=>create_internet_address( '<sender mail id>' ).

lo_bcs->set_senderlo_sender  ).

lo_bcs->set_send_immediately( 'X' ).

*--------------------------------------------------------------------*

*Send Mail

*--------------------------------------------------------------------*

TRY.

     CALL METHOD lo_bcs->send( ).

     COMMIT WORK.

     MESSAGE 'Send Successfully' TYPE 'S'.

   CATCH cx_bcs INTO lo_ex_bcs.

     lv_message = lo_ex_bcs->get_text( ).

     ENDTRY.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
118

Hey Guys,

Finally got an answer to my Question. What a coincidence... I was searching for how to use graphs in email () and from there i came accross this solution for images too.

Everthing is same just instead of attaching the image as an attachment i am using CL_GBT_MULTIRELATED_SERVICE class to add the image as a binary part using method  add_binary_part.

Previous Code(not working on mobile):

Attaching image to the mail


WHILE l_img1 IS NOT INITIAL.

   ls_hex-line = l_img1.

   APPEND ls_hex TO lt_hex1.

   SHIFT l_img1 LEFT BY 255 PLACES IN BYTE MODE.

ENDWHILE.

*Findthe Size of the image

DESCRIBE TABLE lt_hex1 LINES lv_img1_size.

lv_img1_size = lv_img1_size * 255.

*--------------------------------------------------------------------*

*Attach Images

*--------------------------------------------------------------------*

lo_document->add_attachment(

   EXPORTING

     i_attachment_type     'jpg'                  " Document Class for Attachment

     i_attachment_subject  'dh'                " Attachment Title

     i_attachment_size     lv_img1_size           " Size of Document Content

     i_att_content_hex     lt_hex1  " Content (Binary)

).

CLEAR: ls_hex,lv_img1_size.

REFRESH lt_hex1.


New Code (Working on mobile)


CALL METHOD cl_bcs_convert=>xstring_to_solix // converting xstring to solix table type format

     EXPORTING

       iv_xstring = content

     RECEIVING

       et_solix   = it_solix.

   DATA: description TYPE so_obj_des .

   DATA: obj_len     TYPE so_obj_len .

   obj_len = XSTRLEN( content ).

  CONCATENATE lv_image_src '.jpg' INTO lv_image_src.

   CALL METHOD ob_gbt_multirelated_service->add_binary_part // Adding image to the mail

     EXPORTING

       content      = it_solix

       filename     = lv_image_src

       extension    = 'JPG'

       description  = description

       content_type = 'image/jpg'

       length       = obj_len

       content_id   = lv_image_src.



3 REPLIES 3

Juwin
Active Contributor
0 Kudos
118

It may be because of the mobile app being used to view the email.

If the person opens the webmail through mobile, does it show correctly?

Can you send an email from outlook with image in body and see how that appears on the mobile app?

Thanks,

Juwin

Former Member
0 Kudos
118

Juwin,

Thanks for the reply.

yeah we are opening mail on the mobile app... the requirement is like that only to open it on mobile app.I have send a mail with image in the body its appearing as expected  on mobile outlook app.


I think the problem is beacuse of the attachmnents.

The mail which i sent through sap contains attachments which i am placing in the mail body.Attachments are correctly placed in the pc outlook app but not in mobile outlook app.

In mobile its appearing as attachments as shown in screen shot in question.


Thanks

Viplove

Former Member
0 Kudos
119

Hey Guys,

Finally got an answer to my Question. What a coincidence... I was searching for how to use graphs in email () and from there i came accross this solution for images too.

Everthing is same just instead of attaching the image as an attachment i am using CL_GBT_MULTIRELATED_SERVICE class to add the image as a binary part using method  add_binary_part.

Previous Code(not working on mobile):

Attaching image to the mail


WHILE l_img1 IS NOT INITIAL.

   ls_hex-line = l_img1.

   APPEND ls_hex TO lt_hex1.

   SHIFT l_img1 LEFT BY 255 PLACES IN BYTE MODE.

ENDWHILE.

*Findthe Size of the image

DESCRIBE TABLE lt_hex1 LINES lv_img1_size.

lv_img1_size = lv_img1_size * 255.

*--------------------------------------------------------------------*

*Attach Images

*--------------------------------------------------------------------*

lo_document->add_attachment(

   EXPORTING

     i_attachment_type     'jpg'                  " Document Class for Attachment

     i_attachment_subject  'dh'                " Attachment Title

     i_attachment_size     lv_img1_size           " Size of Document Content

     i_att_content_hex     lt_hex1  " Content (Binary)

).

CLEAR: ls_hex,lv_img1_size.

REFRESH lt_hex1.


New Code (Working on mobile)


CALL METHOD cl_bcs_convert=>xstring_to_solix // converting xstring to solix table type format

     EXPORTING

       iv_xstring = content

     RECEIVING

       et_solix   = it_solix.

   DATA: description TYPE so_obj_des .

   DATA: obj_len     TYPE so_obj_len .

   obj_len = XSTRLEN( content ).

  CONCATENATE lv_image_src '.jpg' INTO lv_image_src.

   CALL METHOD ob_gbt_multirelated_service->add_binary_part // Adding image to the mail

     EXPORTING

       content      = it_solix

       filename     = lv_image_src

       extension    = 'JPG'

       description  = description

       content_type = 'image/jpg'

       length       = obj_len

       content_id   = lv_image_src.