Skip to Content

Objective

  • The requirement was to send the Birthday Mails to Employee along with image in mail body. Generally, the images are send as attachment in mail but to send the image in the mail body different approach is to be used.The main objective of this document is to send the image in email body. I searched on portals and google to resolve it but couldn’t find proper solution , so decided to post the document on finding solution.

Challenges

  • To use image in mail there are many options through direct HTML code and CL_BCS class but image appears as attachment and in body “X” icon appears, browsers and mail servers behaves  differently for HTML code.
  • There are four possible solutions according to me


    1. To upload image on any server open to Internet and use that image path in html code. It will work in all case except those were external links are blocked by mail server or the image is removed from the given path.
    2. To convert image to base64 code and append the whole string in image. It will work but string is very long and if not converted properly then image does not appears in mail body as required.
    3. To upload image in smart-form and convert that smart-form to HTML then create html document and embed image to the mail using BCS class. It will work but the limitation is that in smartforms only BMP image types are supported which reduces the quality of image. The styles applied in smartforms are available in html but browsers suppresses the CSS and styles. So no styles will be seen in mail.To use the style they are to be applied inline through html code using tags like <font>,<i>&<b>,etc.
    4. To upload image in MIME Repository. Get the Image from MIME Repository in report and convert it to xstring table form.Using class cl_gbt_multirelated_service combine HTML content and image. Create HTML content and attach image to mail body using BCS class  and assign sender and receivers.


  • The 4th Approach was more feasible and appropriate as it has high availabilty of image in mail body which fulfills the primary requirement.


Advantage

  • It is quite simple and easy approach to embed image in mail body.
  • It can be reused for sending images in mail body.
  • We can give desired styling using inline HTML tags which avoids the usage of css as they are not rendered by many web browsers and mail severs.
  • High availabilty of image in mail and no other objects like smartforms are required,use multiple images in mail body.   

Disadvantage

  • The web browsers and mail severs behave differently while rendering HTML page. We use CID (Context Id ) to display image in HTML body.It is possible that some browsers/mail servers don’t allow to render image in mail body using CID but atleast we would have the image as attachment.


  • Tested for OUTLOOK, ZIMBRA works well on it.


Steps for sending the image in mail

  1. Upload Image in MIME repository.
  2. Get image from mime reporsitory in form of xstring  
  3. Convert the image from xstring to table form ( i.e. solix_tab )
  4. Attach Image in xstring form to HTML form.
  5. Create mail content.
  6. Create HTML form with HTML content.
  7. Create Mail using BCS class.

1. Upload Image in MIME repository.

    

  •      There are many options to upload image in Mime Repository. I have implemented using SE80 TCODE.
  •       It can also be implemented through report using
    • Class : CL_MIME_REPOSITORY_API
    • Method: IF_MR_API~PUT

      1.     Provide TCODE SE80.


      2.     Click on Mime Repository.

     /wp-content/uploads/2013/06/mime2_229787.jpg

      3.     Select Directory where the image is to be uploaded , right click on directory and select “Import MIME Objects” ( Here the directory                is “PUBLIC” ).

       /wp-content/uploads/2013/06/mime3_229789.jpg


     4.     Browse the System and Select the required image to be uploaded from the system then following screen would appear,provide                           description and click on save button.

     /wp-content/uploads/2013/06/mime4_229793.jpg

     5.     On Saving the image the system would prompt for object package , Save it in associated package or local object as per the                                 requirement.


     6.     Now the image would appear in the folder and by clicking on image we can get the preview as shown below.

     /wp-content/uploads/2013/06/mime6_229794.jpg

2. Get image from mime repository in form of xstring


  • Create the report as per the logic required(requirement was to send birthday mails) and we can add the image part and html body      to it
  • Get the image stored in mime repository in the report using 
    • Class: cl_mime_repository_api 
    • Method: if_mr_api~get_api
  • Here in parameter i_url the image path is to be given to obtain the image in xstring form.

  • CODE:

     /wp-content/uploads/2013/06/step2_229799.jpg

3. Convert the image from xstring to table form ( i.e. solix_tab )

  • In variable gv_content the image is in form of xstring.
  • To attach that image in mail we have to convert it to table form of Xstring which contains      row of type xstring and length 255 char


  • The lt_solix table contains the image in xstring table form which would be attached to mail body.
  • CODE

     /wp-content/uploads/2013/06/step3_229800.jpg

4. Attach Image in xstring


  •   In variable l_filename the name is given to the image that is created and in variable      l_content_id the content id (CID) is assigned which   would be later used in the html content.
  • The variable lt_solix contains the image in xstring table form.
  • The variable l_obj_len contains the length of image which was calculated earlier
  • The content type is the mime type of the content in lt_solix
  • For .jpg image it is image/jpg. Similarly for bmp – image/bmp, gif – image/gif , etc
  •   Attach image using 
    • Class : cl_gbt_multirelated_service
    • Method: add_binary_part
    • Object : lo_mime_helper
  • CODE:

     step 4.jpg    


  • If mimetype/content type is not available in system then we need to add it through following steps

           TCODE : SMW0.

    

                1. Execute TCODE : SMW0

                      step 4 1.jpg

               2. Press F8           

                              step 4 2.jpg

 

                3. Press F8

                      step 4 3.png

            4. In Menu , Goto Settings –> Maintain MIME Types.Click on Create button

                    step 4 4.jpg

    • If the desired mime type is not present then the required mime type can be created using above steps

 

5. Create HTML mail content.


  • The HTML content is prepared and filled in table lt_soli which would be later used to create      HTML form.
  • <font> tag is used to use to give the style to the content.
  • <img> tag is used for using image in html body.
  • In <img> the content id (CID) should be same as the content Id given in above step while      attaching image.
  • Code:

          step 5.jpg                                                         

         6.Create HTML form with HTML content.


  •      The created html content in table lt_soli is to be attached to create a HTML form using
      • Class : cl_gbt_multirelated_service
      • Method: set_main_html
      • Object : lo_mime_helper
  •     Code

               step 6.jpg

7. Create Mail using BCS class.

  • Now using the CL_BCS class we can embed html body and image assigning sender and      receivers.
  • Code:

          step 7.jpg

Output in SOST.

          /wp-content/uploads/2013/06/image1_231323.jpg

Output in Mail Client.

            /wp-content/uploads/2013/06/image2_231332.jpg

The Source Code is attached in a text file.

cheers!!!

To report this post you need to login first.

50 Comments

You must be Logged on to comment or reply to a post.

  1. Christian Guenter

    Hi Purvang,

    nice Blog.

    You can replace the code in step 3 with a call to the class-method XSTRING_TO_SOLIX from class CL_BCS_CONVERT.

    This makes your code cleaner, less error prone and saves you some work. Just don’t reinvent the wheel.

    Regards Christian

    (0) 
  2. Jelena Perfiljeva

    Thank you for sharing! I especially liked how you outlined all the steps first and then went into details. Well done.

    Maybe some kind of a web service to call Someecards would be a good alternative, er? 🙂

    (0) 
    1. Purvang Gandhi Post author

      Hi Jelena,

      I think that for using web service for calling e-cards would work if the mail servers allow to the access to other/private web services.

      Thanks for the suggestion would try that way. 🙂

      (0) 
  3. shravan kumar

    Hi Purvang,

    Thanks for sharing this, just the couple of days back, i got the same requirement and i am working on it. Now you made my work easy.

    Cheers for you…

    (0) 
  4. Ravi Shankar

    Hi,

    I have tried to send the logo to my gmail id and outlook still it is coming as attached file only not in the body of the mail can you please help me I have attached the screenshot here.

      Even in SOST image is not showing me as per your screen shoot.Please help me.

    Regards,

    Ravi Shankar L

    (0) 
    1. Jayakumar K B

      Just check the HTML part  for the Image File.

      confirm the same name throughout the program. that will solve this issue. please check the underlined part of your code.

      CALL METHOD gv_mr_api->get

         EXPORTING

           i_url = ‘/SAP/PUBLIC/turtle.jpg’ “Image path

         IMPORTING

           e_is_folder = is_folder

           e_content = gv_content

           e_loio = l_loio

         EXCEPTIONS

        parameter_missing  = 1

           error_occured = 2

           not_found = 3

        permission_failure = 4

           OTHERS = 5.

      l_filename = ‘turtle.jpg’.

      l_content_id = ‘turtle.jpg’.

      ls_soli = ‘<br><img  src=”turtle.jpg” width = “150px” height = “150px”/><br>’.

      (0) 
      1. Ravi Shankar

        Hi Jayakumar,

        CALL METHOD gv_mr_api->get

           EXPORTING

             i_url = ‘/SAP/PUBLIC/ZSG_LOGOS/ZWeber_Logo.jpg’  “Image path

        *Attach image to HTML body

        l_filename = ‘ZSG_LOGOS/ZWeber_Logo.jpg’.

        l_content_id = ‘ZSG_LOGOS/ZWeber_Logo.jpg’.

        “For displaying Image

        CLEAR ls_soli.

        *ls_soli = ‘<lt;br><lt;img alt=”[image]” src=”cid:ZSG_LOGOS/ZWeber_Logo.jpg” /><lt;br>’.

        ls_soli = ‘<br><img  src=”ZSG_LOGOS/ZWeber_Logo.jpg” width = “150px” height = “150px”/><br>’.

        APPEND ls_soli TO lt_soli.

        I am getting frame allocated for that image but image is not placing there

        Dear Ravi Shankar ,

        Regards, Testing Team Sigma

        Still mail is sending only in attachment please help me…… what mistake I am doing here…

        Regards,

        Ravi Shankar L



        (0) 
        1. Purvang Gandhi Post author

          Hi Ravi,

          Please check if file name & content id is added as below

          l_filename = ‘ZSG_LOGOS/ZWeber_Logo.jpg’.
          l_content_id = ‘ZSG_LOGOS/ZWeber_Logo.jpg’.

          CREATE OBJECT lo_mime_helper.
          CALL METHOD lo_mime_helper->add_binary_part
            EXPORTING
              content      = lt_solix                   “Xstring in table form
              filename     = l_filename                 “file name to be given to image
              extension    = ‘JPG’                      “type of file
              description  = ‘Graphic in JPG format’    “description
              content_type = ‘image/jpg’                “content type / Mime type. If mime type not present in system     length       = l_obj_len                  “length of image
              content_id   = l_content_id.              “content id would be used in html part

          If it’s fine then try inserting below line for image

          ‘<br><img alt=”[image]” src=”cid:ZSG_LOGOS/ZWeber_Logo.jpg” /><br>’

          I think the problem is in HTML code.

          If problem still persists you can mail me
          that part of code if it’s fine for you so
          that I can check code.

          Regards
          Purvang

          (0) 
  5. Virendra Kedia

    Nice one Dear!

    Very useful. Can you please help me in the below scenario?

    I want to convert some texts, tables into an image file dynamically and then use that image to make a PDF file so that my PDF file will not be editable even someone has opened it with any editor tool.

    Can we do that? If yes, then how?

    Thanks and Regards,

    Virendra Kedia

    (0) 
    1. Purvang Gandhi Post author

      Hi Virendra,

      If your primary requirement is to make PDF non editable then please go for digitally signed PDF or making it password protect or using SSF(provided by SAP) it would be more secured.

      Even there are tools available which would read text from images in PDF.

      I haven’t came across any such class or method to convert text/tables to an image will search on it and let you know if I find any.

      You can use any third party tool (many are online) to convert text to image and save those images somewhere either in MIME repository or Application server.

      You can upload this image to smart-form and then convert smart-form to PDF or other way is to convert image to binary content and then convert the binary content to PDF(OTF).

      Hope this helps!!!! 🙂

      Thanks & Regards

      purvang

      (0) 
  6. Ravi Shankar

    I got one more spark from this link….. It is possible to upload video files “*.avi,etc” in MIME repository if we click it from there means video running succesfully same way If I press some button I need to play that video…..  If any one have idea about it please share it…  Thanks in advance.

    Regards,

    Ravi Shankar L

    (0) 
    1. Purvang Gandhi Post author

      Hi Ravi,

      I tried uploading AVI file in MIME Repository and it works.

      We just need to add a MIME Type(*.avi) as I mentioned in the document through transaction SMW0 the same way as we did for images.

      On clicking the AVI file it will open on your PC’s default media player and start playing.

      check the below link to have your media player in SAP it would be fun :

      http://scn.sap.com/people/thomas.jung/blog/2005/05/11/using-classic-activex-controls-in-the-abap-control-framework

      Thanks & Regards

      purvang

      (0) 
      1. Ravi Shankar

        I am trying to play this video file if I click one button in report it want to run it is possible? IN MIME it running successfully from program I need to call this If you have any idea please share me….

        (0) 
  7. Manish Kumar

    Hi Purvang,

    Have got same requirement where need to send image in the body of email with text (below image)

    Pls check below code ,i m  not getting image in the body  it is showing as X mark

    there is part of code mentioned above in the post which i have commented as it was showing junk character in Email

    Thanks in advance.

    REPORT ZTEST1.

    INCLUDE ZTEST1I.*all data declaration part done inside include

    *Create image in xstring form

    IF gv_mr_api IS INITIAL.

    gv_mr_api = cl_mime_repository_api=>if_mr_api~get_api( ).

    ENDIF.

    CALL METHOD gv_mr_api->get
    EXPORTING
    i_url
    = ‘/SAP/PUBLIC/zlogo/xyz.jpg’  “Image path
    IMPORTING
    e_is_folder
    = is_folder
    e_content
    = gv_content
    e_loio
    = l_loio
    EXCEPTIONS
    parameter_missing 
    = 1
    error_occured
    = 2
    not_found
    = 3
    permission_failure
    = 4
    OTHERS = 5.

    “Convert Image to Xstring table form

    l_obj_len = XSTRLEN( gv_content ).
    lv_graphic_length
    = XSTRLEN( gv_content ).

    “get whole image
    CLEAR gr_xstr.
    gr_xstr
    = gv_content(l_obj_len).

    l_offset = 0.
    l_length
    = 255.

    CLEAR lt_solix[].
    WHILE l_offset < lv_graphic_length.
    l_diff
    = lv_graphic_length l_offset.
    IF l_diff > l_length.
    ls_solix
    line = gr_xstr+l_offset(l_length).
    ELSE.
    ls_solix
    line = gr_xstr+l_offset(l_diff).
    ENDIF.
    APPEND ls_solix TO lt_solix.
    ADD l_length TO l_offset.
    ENDWHILE.

    CALL FUNCTION ‘SSFC_BASE64_ENCODE’
    EXPORTING
    BINDATA                       
    = gv_content
    IMPORTING
    B64DATA                       
    = gv_content_64
    EXCEPTIONS
    SSF_KRN_ERROR                 
    = 1
    SSF_KRN_NOOP                  
    = 2
    SSF_KRN_NOMEMORY              
    = 3
    SSF_KRN_OPINV                 
    = 4
    SSF_KRN_INPUT_DATA_ERROR      
    = 5
    SSF_KRN_INVALID_PAR           
    = 6
    SSF_KRN_INVALID_PARLEN        
    = 7
    OTHERS                         = 8
    .
    IF SYSUBRC <> 0.
    * Implement suitable error handling here
    ENDIF.

    *Attach image to HTML body
    l_filename
    = ‘zlogo/xyz.jpg’.
    l_content_id
    = ‘zlogo/xyz.jpg’.

    CREATE OBJECT lo_mime_helper.

    CALL METHOD lo_mime_helper->add_binary_part
    EXPORTING
    content
    = lt_solix                   “Xstring in table form
    filename
    = l_filename                 “file name to be given to image
    extension
    = ‘JPG’                      “type of file
    description
    = ‘Graphic in JPG format’    “description
    content_type
    = ‘image/jpg’                “content type / Mime type. If mime type not present in system then need to add through tcode : SMW0
    length
    = l_obj_len                  “length of image
    content_id
    = l_content_id.              “content id would be used in html part

    “Create HTML mail body Content
    REFRESH lt_soli[].
    CLEAR ls_soli.

    *****************************************************HTML body content start**************************************************************************
    ls_soli
    = ‘<html xmlns=”http://www.w3.org/1999/xhtml” xmlns:xfa=”http://www.xfa.org/schema/xfa-template/2.1/“>’ .
    APPEND ls_soli TO lt_soli.
    CLEAR ls_soli.

    ls_soli = ‘<html>’.
    APPEND ls_soli TO lt_soli.

    CLEAR ls_soli.

    ls_soli = ‘<body>’.
    APPEND ls_soli TO lt_soli.

    CLEAR ls_soli.

    *commented this part as was getting junk text in mail

    *ls_soli  = ‘< style=”font-family:verdana;font-size:15px;”>’  .
    *APPEND ls_soli TO lt_soli.
    *
    *CLEAR ls_soli.

    * lv_length = STRLEN( gv_content_64 ).
    * lv_len2 = lv_length / 255.
    * ls_soli = gv_content_64.
    * APPEND ls_soli TO lt_soli.

    *CLEAR ls_soli.
    *
    * DO lv_len2 TIMES.
    *
    * lv_len3 = 255 * sy-index.
    * IF lv_len3 <= lv_length.
    *  ls_solixr-line = gv_content_64(lv_len3).
    *      IF ls_solixr IS NOT INITIAL.
    *     MOVE ls_solixr-line TO ls_soli-line.
    *     APPEND ls_soli TO lt_soli.
    *     CLEAR lt_soli.
    *    ELSE.
    *       EXIT.
    *      ENDIF.
    *ELSEif lv_len3 > lv_length.
    *    EXIT.
    *ENDIF.
    *ENDDO.

    *end of commented code

    CLEAR ls_soli.

    ls_soli = ‘<img src=”cid:zlogo/xyz.jpg”>’.
    APPEND ls_soli TO lt_soli.
    clear ls_soli .

    ls_soli = ‘<BR> <BR> <BR> ‘ .

    APPEND ls_soli TO lt_soli.

    clear ls_soli .

    ls_soli = ‘ <p>   Dear Name1,  <BR> <BR>  the Following request requires your Attention: <BR> <BR> ‘ .

    APPEND ls_soli TO lt_soli.

    clear ls_soli .

    ls_soli = ‘ Request Number : <U> Ticket number </U> <BR> Request Type : Category <BR> Description: Test <BR> Current Status: Status <BR> </p> ‘  .

    APPEND ls_soli TO lt_soli.

    clear ls_soli .

    ls_Soli = ‘ <BR> <BR> <P1> <Strong> Action Team </Strong> </P1> <BR> <BR> ‘  .

    APPEND ls_soli TO lt_soli.

    clear ls_soli .

    ls_soli = ‘<h2 style=”background-color:yellow;”>’ .

    APPEND ls_soli TO lt_soli.
    clear ls_soli .

    ls_soli = ‘ <P2> <font color = “#0000FF” size=”+1″ face=”Arial,”Helvetica, sans-serif”   <BR>  This is an automatically generated message. Please do not reply to this address.  <BR> ‘ .

    APPEND ls_soli TO lt_soli.
    clear ls_soli .

    ls_soli = ‘ </body> ‘ .

    APPEND ls_soli TO lt_soli.
    clear ls_soli .

    ls_soli = ‘ </html> ‘ .

    APPEND ls_soli TO lt_soli.
    clear ls_soli .

    DATA : title type c LENGTH 100.

    CONCATENATE ‘ticketnumber-status’ ‘requires your attention’  INTO title SEPARATED BY space.

    *CREATE OBJECT lo_mime_helper.

    CALL METHOD lo_mime_helper->set_main_html
    EXPORTING
    content
    = lt_soli
    filename
    = ‘sapwebform.htm’      “filename for HMTL form
    description
    = ‘Ticket Alert’“Title

    “Create HTML using BCS class and attach html and image part to it.
    l_subject
    = title“subject
    lo_doc_bcs
    = cl_document_bcs=>create_from_multirelated(
    i_subject
    = l_subject
    i_multirel_service
    = lo_mime_helper ).

    lo_bcs = cl_bcs=>create_persistent( ).

    “Create Document
    lo_bcs
    ->set_document( i_document = lo_doc_bcs ).

    “create Sender
    lo_sender
    = cl_cam_address_bcs=>create_internet_address( ‘xyz@xyz.com).

    “Create Recipient
    lo_recipient
    = cl_cam_address_bcs=>create_internet_address( i_address_string = ‘xyz@xyz.com).
    lo_bcs
    ->add_recipient( i_recipient = lo_recipient ).

    lo_bcs->send( ).
    COMMIT WORK AND WAIT.

    (0) 
  8. Shubhra Gulati

    A very good solution. Thanks for sharing.

    I am able to see the image in SOST but in outlook I am getting 2 attachments:-

    i) sapwebform.htm

    ii) photo.jpg.

    But I need the image in mail content. Please help.

    (0) 
    1. Jahnavi Priya

       

      Hello.

      Please let me know if anyone found the solution for the same. I took the help of the blog above. It works perfectly if I open my emails in Web Browser but when I open it in Outlook , I get two attachments .

      Please let me know how to solve the issue.

      Thanks

      (0) 
  9. V N

    Hi Purvang,

    Thanks for the documentation it is really good.

    I have also same requirement but when i try to execute the program the image is attached in the mail and not showing in body but a icon  with a cross sign is displayed in the body.

    Please help if you can. I am pasting my code below.

    Thanks in advance.

    REPORT ZTEST_IT.

    “For Mime Repository

    DATA : gv_mr_api TYPE REF TO if_mr_api, “mime repository object

            gv_content TYPE xstring,  “image in XSTRING

            is_folder TYPE boole_d,

            l_loio TYPE skwf_io.

    “source Code for image in mail body by Purvang Gandhi

    “Image to Xstring Table form

    DATA : l_obj_len      TYPE so_obj_len,

      lv_graphic_length TYPE tdlength,

            gr_xstr TYPE xstring,

            l_offset TYPE i,

            l_length TYPE i,

            l_diff TYPE i,

            ls_solix TYPE solix,

            lt_solix TYPE solix_tab.

    *Attach image to HTML body

    DATA: l_filename     TYPE string,

           l_content_id TYPE string.

    “for HTML content

      data : lt_soli        TYPE soli_tab,

             ls_soli TYPE soli.

    *Class for cobining HMTL & Image

    DATA : lo_mime_helper    TYPE REF TO cl_gbt_multirelated_service.

    *BCS class for sending mail

    data: lo_bcs            TYPE REF TO cl_bcs,

            lo_doc_bcs TYPE REF TO cl_document_bcs,

            lo_sender TYPE REF TO if_sender_bcs,

      lo_recipient      TYPE REF TO if_recipient_bcs,

            l_subject TYPE so_obj_des.

    “Create image in xstring form

    IF gv_mr_api IS INITIAL.

       gv_mr_api = cl_mime_repository_api=>if_mr_api~get_api( ).

    ENDIF.

    CALL METHOD gv_mr_api->get

       EXPORTING

         i_url = ‘/SAP/PUBLIC/Happy.jpg’  “Image path

       IMPORTING

         e_is_folder = is_folder

         e_content = gv_content

         e_loio = l_loio

       EXCEPTIONS

      parameter_missing  = 1

         error_occured = 2

         not_found = 3

      permission_failure = 4

         OTHERS = 5.

    “Convert Image to Xstring table form

    l_obj_len = XSTRLEN( gv_content ).

    lv_graphic_length = XSTRLEN( gv_content ).

    “get whole image

    CLEAR gr_xstr.

    gr_xstr = gv_content(l_obj_len).

    l_offset = 0.

    l_length = 255.

    CLEAR lt_solix[].

    WHILE l_offset lt lv_graphic_length.

       l_diff = lv_graphic_length – l_offset.

       IF l_diff > l_length.

         ls_solix-line = gr_xstr+l_offset(l_length).

       ELSE.

         ls_solix-line = gr_xstr+l_offset(l_diff).

       ENDIF.

       APPEND ls_solix TO lt_solix.

       ADD l_length TO l_offset.

    ENDWHILE.

    *Attach image to HTML body

    l_filename = ‘img_happy.jpg’.

    l_content_id = ‘img_happy.jpg’.

    CREATE OBJECT lo_mime_helper.

    CALL METHOD lo_mime_helper->add_binary_part

       EXPORTING

         content = lt_solix                   “Xstring in table form

         filename = l_filename                 “file name to be given to image

         extension = ‘JPG’                      “type of file

         description = ‘Graphic in JPG format’    “description

         content_type = ‘image/jpg’                “content type / Mime type. If mime type not present in system then need to add through tcode : SMW0

         length = l_obj_len                  “length of image

         content_id = l_content_id.              “content id would be used in html part

    “Create HTML mail body Content

    REFRESH lt_soli[].

    CLEAR ls_soli.

    ls_soli = ‘<html xmlns=”http://www.w3.org/1999/xhtml” xmlns:xfa=”http://www.xfa.org/schema/xfa-template/2.1/“><head></head>’.

    APPEND ls_soli TO lt_soli.

    CLEAR ls_soli.

    ls_soli = ‘<body>’.

    APPEND ls_soli TO lt_soli.

    “to apply font to HTML body content

    CLEAR ls_soli.

    CONCATENATE ‘<p><font size=”4″ face=”Gabriola,Lucida Calligraphy,Comic Sans MS” color=”red” fontStyle=”italic”><i><b>Dear’

      ‘Employee Name’ ‘, <br>’ INTO ls_soli SEPARATED BY space.

    APPEND ls_soli TO lt_soli.

    “For displaying Image

    CLEAR ls_soli.

    ls_soli = ‘<br><img alt=”[image]” src=”cid:happy.jpg” /><br>’.

    APPEND ls_soli TO lt_soli.

    CLEAR ls_soli.

    CONCATENATE ‘<br>Regards,<br>’ ‘CEO Name’ ‘<br>Team GINGER</b></i></font></p></body></html>’

                 INTO ls_soli SEPARATED BY space.

    APPEND ls_soli TO lt_soli.

    “Create main HTML body

    *CREATE OBJECT lo_mime_helper.

    CALL METHOD lo_mime_helper->set_main_html

       EXPORTING

         content = lt_soli

    *    filename = ‘sapwebform.htm’      “filename for HMTL form

         description = ‘Birthday Greeting’“Title

    “Create HTML using BCS class and attach html and image part to it.

    l_subject = ‘Birthday Greetings’(t01).  “subject

    lo_doc_bcs = cl_document_bcs=>create_from_multirelated( i_subject = l_subject i_multirel_service = lo_mime_helper ).

    lo_bcs = cl_bcs=>create_persistent( ).

    “Create Document

    lo_bcs->set_document( i_document = lo_doc_bcs ).

    “create Sender

    *lo_sender = cl_cam_address_bcs=>create_internet_address( ‘xyz@abc.com‘ ).

    *

    ** Set sender

    *lo_bcs->set_sender( EXPORTING i_sender = lo_sender ).

    “Create Recipient

    lo_recipient = cl_cam_address_bcs=>create_internet_address( i_address_string = ‘xyz@abc.com).

    lo_bcs->add_recipient( i_recipient = lo_recipient ).

         IF lo_bcs->send( ) IS INITIAL.

             ELSE.

             COMMIT WORK.

           ENDIF.

    WAIT UP TO 2 SECONDS.

       SUBMIT rsconn01 WITH mode = ‘INT’

                     WITH output = ‘X’

                     AND RETURN.

    *COMMIT WORK AND WAIT.

    (0) 
    1. Shilpi Gupta

      Hi,

      I am also getting the same issue, image is not being displayed in email body but a place holder with cross sign is being displayed. Also the image doesn’t comes as an attachment. It would be of great help if someone can guide me through the solution.

      Thanks

      (0) 
  10. pr murthy

    Hi Puvang,

    Thank you so much for the post.

    I was trying to fulfill a requirement where I need to send a Smartform ( Converted to PDF ) as attachment along with the mail body where there is logo in the signature section.

    The approach mentioned by you works perfectly for email body part.

    But the problem I face is the attachment handles by the below piece of code does not work.

    lo_doc_bcs1->add_attachment(

            i_attachment_type      ‘PDF’

            i_attachment_subject  gv_title

            i_attachment_size      =   lv_len
    i_att_content_hex 
    =   li_content_hex ).

    Can you suggest what could be done here.

    Regards,

    Rama Murthy

    (0) 
    1. Virgilio Israel Morales

      Hi Rama.

      Did you change the bin file to binary tab on previous steps?

      Generally below are the steps i made:

      1. i used the CONVERT_OTF function

      CALL FUNCTION ‘CONVERT_OTF’

           EXPORTING

             format                = ‘PDF’

             max_linewidth         = 132

           IMPORTING

             bin_filesize          = bin_size

             bin_file              = pdf_xstring

           TABLES

             otf                   = t_otf

             lines                 = t_pdf_tab

           EXCEPTIONS

             err_max_linewidth     = 1

             err_format            = 2

             err_conv_not_possible = 3

             OTHERS                = 4.


      2. Once i get the bin file, i changed the bin_file to binary tab with CMS_XSTRING_TO_BINARY

      DATA:  l_size      TYPE soodobjlen,

      CALL FUNCTION ‘SCMS_XSTRING_TO_BINARY’

               EXPORTING

                 buffer        = pdf_xstring

               IMPORTING

                 output_length = len_size

               TABLES

                 binary_tab    = pdf_content.

      MOVE len_size TO l_size.

      3.Finally you should be able to attach you document in the email with the same function you are using


      CALL METHOD l_document->add_attachment

               EXPORTING

                 i_attachment_type    = ‘PDF’

                 i_attachment_size    = l_size

                 i_att_content_hex    = pdf_content.


      Hope this helps.


      Have a nice weekend.

      (0) 
        1. Tanju Lise

          Hi Murthy,

          I have got same problem .

          I saw your message when I check the sdn.

          So, please tell me first of what did you do ?

          I mean you when you use CONVERT OTF function you are saying PDF..

          You mean are your grafic  a PDF format  ?

          And did you do MIME Repository  working using se80?

          Wouıld you please write me how can I start before writing this code  ?

          I will appreciate …

          Thanks

          Regards

          Tanju

          (0) 
  11. Tanju Lise

    Hi Purvang,

    Great working, well done …

    Please let me ask a question for you .

    I am attaching PDF files and sending , there is no any problem.

    But my problem is there is jpg files and PDF files sending together.

    I am using the function ‘SO_DOCUMENT_SEND_API1’  ..

    So My question, how can I send together ?

    I mean how can start first of all ?

    Am I use MIME Repository ?

    May I use MIME Repository and SO_DOCUMENT_SEND_API1 together ?

    Is this right ?

    Or is this wrong how can I start ?

    Well, in fact I opened a new incident in SDN, but unfortunately it was removed cause of rules.

    I did not understand why ?

    If you help me I am reallly appreciate 

    Regards

    Tanju

    (0) 
  12. siva 9533

    Hi ,

    it is working fine with one IMAGE,but it is not working with multiple IMAGES . Can some one help how to work with multiple images using MIME helper .

    Regards,

    Siva Krishna

    (0) 
      1. siva 9533

        Hi Tanju,

        you got it means , you are able to get multiple images using MIME helper?

        if yes

        can you please help me to get it.

        Regards,

        Siva

        (0) 
  13. siva 9533

    I tried in different way to attach multiple images but those are working fine in outlook but not working properly in SOST and Webmail ( Mail Box in Internet explorer ) are not working fine.

    Please open the below link for more details.

    Email Preview in SOST

    (0) 
      1. siva 9533

        Many many thanks Tanju.

        it worked as what I have expected.

        Thank you very much appreciated your help.

        Regards,

        Siva Krishna

        (0) 
          1. siva 9533

            Hi Tanju,

            I have one more last request , Email body is showing perfectly in English language where it it not showing correctly in other languages .

            Example :

            Text in Mail :-

            Text in English  :   Thank you for your           

            Text in German  :  vielen Dank für Ihre

            Text in SOST  Display :-

            Text in English  :   Thank you for your           

            Text in German  :  vielen Dank für Ihre

            Regards,

            Siva Krishna


            (0) 
  14. Ravi Kumar

    Hi Gurus,

    I have imported the image in MIME Repository and used in the email attachment. Everything is working fine, and image is displaying in Email (using this in CRM WebUI flow logic)when I execute the flow.

    But when the Business users in CRM WebUI execute the logic, the image is not rendering for some users.

    Is there any authorization issue or any other? Please help!!!

     

    Thanks in advance.

    (0) 
  15. krishna joshi

    Hi All,

     

    I can see in the blog, it is mentioned that code is attached in text file. However i do not see the text attachment.

    Can anyone please help me with the full code for this?

    (0) 

Leave a Reply