+ All Categories
Home > Documents > How to Send Image in sap

How to Send Image in sap

Date post: 30-Oct-2015
Category:
Upload: ricky-das
View: 316 times
Download: 2 times
Share this document with a friend
Description:
How to Send Image in sap

of 12

Transcript

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 Touse image in mail there are many options through direct HTML code andCL_BCSclass 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 usingBCSclass. It will work but the limitation is that insmartformsonlyBMPimage types are supported which reduces the quality of image. The styles applied insmartformsare 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 ,&,etc.4. To upload image in MIME Repository. Get the Image from MIME Repository in report and convert it toxstringtable form.Using classcl_gbt_multirelated_servicecombine HTML content and image. Create HTML content and attach image to mail body usingBCSclass and assign sender and receivers. The 4thApproach was more feasible and appropriate as it has highavailabiltyof 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 ofcssas they are not rendered by many web browsers and mail severs. Highavailabiltyof image in mail and no otherobjectslikesmartformsare required,use multiple images in mail body.Disadvantage The web browsers and mail severs behave differently while rendering HTML page.We useCID(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 usingCIDbutatleastwe would have the image as attachment. Tested forOUTLOOK, ZIMBRAworks well on it.Steps for sending the image in mail.1. Upload Image in MIME repository.2. Get image from mimereporsitoryin form of xstring3. Convert the image fromxstringto table form (i.e.solix_tab )4. Attach Image inxstringform to HTML form.5. Create mail content.6. Create HTML form with HTML content.7. Create Mail usingBCSclass.1. Upload Image in MIME repository. There are many options to upload image in Mime Repository. I have implemented usingSE80TCODE. It can also be implemented through report using Class :CL_MIME_REPOSITORY_API Method:IF_MR_API~PUT 1. ProvideTCODESE80. 2. Click onMime Repository. 3. Select Directory where the image is to be uploaded , right click on directory andselect "Import MIME Objects" ( Here the directory is "PUBLIC"). 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. 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.2. Get image from mimerepositoryin 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 parameteri_urlthe image path is to be given to obtain the image inxstringform. CODE:3. Convert the image fromxstringto table form (i.e.solix_tab ) In variablegv_contentthe image is in form ofxstring. To attach that image in mail we have to convert it to table form ofXstringwhich contains row of typexstringand length 255 char Thelt_solixtable contains the image inxstringtable form which would beattached to mail body. CODE4. Attach Image inxstring In variablel_filenamethe name is given to the image that is created and in variablel_content_idthe content id (CID) is assigned which would be later used in the html content. The variablelt_solixcontainsthe image inxstringtable form. The variablel_obj_lencontains the length of image which was calculated earlier The content type is the mime type of the content inlt_solix For .jpgimage 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: Ifmimetype/content type is not available in system then we need to add it through following stepsTCODE: SMW0.1. ExecuteTCODE: SMW0 2. Press F8 3. Press F8 4. In Menu ,GotoSettings --> Maintain MIME Types.Click on Create button If the desired mime type is not present then the required mime type can be created using above steps5. Create HTML mail content. The HTML content is prepared and filled in tablelt_soliwhich would be later used to create HTML form. tag is used to use to give the style to the content. tag is used for using image in html body. In the content id (CID) should be same as the content Id given in above step while attaching image. Code: 6.Create HTML form with HTML content. The created html content in table lt_soli is to be attached to create a HTML formusing Class :cl_gbt_multirelated_service Method:set_main_html Object :lo_mime_helper Code7. Create Mail usingBCSclass. Now using theCL_BCSclass we can embed html body and image assigning sender and receivers. Code:Output in SOST.Output in Mail Client.


Recommended