Skip to Content
Introduction
There seems to be a lot of requests in the forums for tips on how to send E-Mail from ABAP. Based upon these requests, I thought I would pull together some resources and samples on the subject. The setup and samples are quite different on different releases. This first weblog will cover SAP Basis releases 46D and lower. All samples came from a 46C system (Although the ABAP code is very much the same as the code we used to use back on our old 3.1H system). There will be another weblog later that covers this same topic for WebAS Version 610 and higher.

Configuration
Before we start with any ABAP coding, we first have to setup and configure a few things. Much of this configuration may have already been completed by your Basis group.

Internet Mail Gateway
The first thing we want to setup is probably the Internet Mail Gateway. Since the Basis layer at these releases doesn’t have any native SMTP abilities we will need an executable at the OS level to perform the sending of the mail for us. These executables are commonly referred to as the Internet Mail Gateway. I suggest that anyone doing this setup start by reading OSS note 99965. This has a quite good, step-by-step implementation guide to setting up the Internet Mail Gateway. To complete this part of the setup we need to make sure that we have our mail gateway configuration file (default name mailgw.ini) setup and available to the executables. That means using one of the two default directories or the GWCONFIG environment variable. The configuration file can be created or modified using the program MLSOMADM. Finally we need to make sure that we have the program that does the mail sending itself: MLUNXSND. If you need to know where you can go to get the latest patch level of these executables, please read OSS note 101573.

RFC Connection
Next we need to configure a RFC destination so that we can exposed these executables to ABAP. The instructions in OSS note 99965 describe setting up this TCP/IP RFC destination as Direct Start or via Registration. The following is a screen shot of our RFC Destination. We use the Direct Start Option, calling a shell script as described in the OSS Note:
image

SAPConnect
Well we are finished with all the low level setup. Now we need to connect the lowest layer (the Internet Mail Gateway) to SAP’s middle message layer: SAPConnect. SAPConnect sits between the application layer (such as SAP Office) and the lowest layer hiding all the technical details. All of the SAPConnect monitoring and configuration can be reached from one transaction called SCOT. First SCOT has several different views that can be used. One shows the Jobs that have been setup, the other shows setup by routings, etc. I prefer to start SCOT in System Status View. This shows a tree with the communication types, the nodes setup for each type and the number of messages in each status. The following is a screen shot of this view:
image

We want to create a new node in SAPConnect for our E-Mail. In 46C you have a quite nice Wizard that walks you through the process. However you can also control all settings directly in a dialog maintenance window. This is a screen shot of our Email Node.
image
image

You can see at this point we connect the processing for this node to our RFC destination setup before. You also can set the supported address types and their settings.

For the supported address type of Internet, we really have a very plain setup. We don’t do any outbound filtering to different nodes. Therefore the address areas is set to the wildcard ‘*’. We support all formats except those listed in OSS note 99965 (ALI, SCR, OTF, OBJ and URL) and use the PDF device type to format outputs. If you are interested in PDF Device Type in 46C or lower have a look at OSS note 317851.
image
image

One special note on code pages. If you are a MDMP system or you use a double byte code page, I’m afraid you could be in a little bit of trouble. Have a look at OSS note 331418 for the details on the support (or lack there of) for these special code page situations. I can tell you that the 610 and higher mail interface does solve this problem.

Next we need to schedule a job that will transmit out E-mails. E-Mails will only go out when this job runs, so you probably want to schedule it quite frequently. In our production system we run this job every 5 minutes. The job setup can also be done from SCOT. Switch your view to JOBS. You can then hit CREATE to start the process of scheduling a new Send Job.

Running a Test
We are just about ready to run our first test. The only other requirement is that the sender of any E-mail, must have their return address setup in their user master. If you don’t maintain this data, you will get a send error. If you want an SAP program to generate these addresses for you, have a look at OSS note 104263. Also in 46C you have the option to configure the system to generate the sender address on the fly. OSS note 320443 gives you the details of this solution. You can see from the following screen shot the field that must be maintained in the user master:
image

Let’s try a test now. I like to start by testing using the SAP short message functionality. You will want to use menu System->Short Message. From here we will prepare a short test message. If you don’t want to wait for your batch job to run to find out if your message went through, just jump back to transaction SCOT. From the System Status view you can choose Ctrl+F7 or the Execute Icon to start the send process for a communication type. You should receive you test message if everything is setup fine.

Trouble Shooting
Let’s say that everything didn’t go fine. Where do we start trouble shooting? Once again start with the transaction SCOT. The system status shows us our status overview. You can see the number of messages in Error or Waiting. If you have a lot of messages in Waiting status, your send job probably isn’t scheduled.

The overview screen is nice, but you probably want more details. From SCOT you can choose Utilities->Overview of Send Orders (Or Tcode SOST). This transaction will give a detailed report by Address type, status, date, time and sender. For each message we can view the transmission history, the message itself, and the tracelog. You can also try and resubmit the message from here.

If you need to activate tracing, you want to return to transaction SCOT. You then choose Utilities->Trace->Internal Trace. You can also view all traces from here without having to go through SOST.

ABAP Coding
If everything has worked up to this point, then you are ready to start writing your own E-mail calls in ABAP. There are two SAP function modules that are commonly used: SO_NEW_DOCUMENT_ATT_SEND_API1 and SO_NEW_DOCUMENT_SEND_API1. The main difference between these two function modules is that SO_NEW_DOCUMENT_ATT_SEND_API1 allows you to send attachments along with your message. This is especially useful for including outputs and reports in your e-mail. To tell you the truth though, I always use SO_NEW_DOCUMENT_ATT_SEND_API1 even if I don’t have any attachments. This just keeps my code very similar from application to application (I have a habit of cutting and pasting the email code most of the time).
Both of these function modules are quite well documented in SE80. The document even includes a sample program. The key to using this function module is putting your content for your email in the correct place. You have three “contents” table parameters: CONTENTS_BIN, CONTENTS_TXT, and CONTENTS_HEX. CONTENTS_TXT contains all you ASCII text based content. CONTENTS_BIN and CONTENTS_HEX are for binary based data such as PDF document attachments. You can use CONTENTS_HEX, however if you do the function will clear CONTENTS_BIN and copy CONTENTS_HEX to CONTENTS_BIN. I generally just focus on CONTENTS_BIN and CONTENTS_TXT. The key here is that all of your content must go into these two tables. Let’s assume that you have two PDF file attachments that you want to send. The binary data for both attachments must be put into the single instance of the CONTENTS_BIN table parameter.

This is where another table parameter called the PACKING_LIST comes into play. The PACKING_LIST will be used by the function module to break up the individual pieces of content that are all forced together in your CONTENTS_BIN and CONTENTS_HEX files. Each piece of content should have a single record in the PACKING_LIST that specifies the content type (binary or ASCII), the starting position, the size, the name, etc. In the end this allows for a very flexible (but slightly complicated) E-mail interface.

The following is a simple code sample to complement the ones from the SAP help. I will create a simple mail message. In addition I will take a spool output and convert it to HTML and attach it to my message.

Global Data Statement
The following are my global data statements. You will see that I declare areas for my Packing List (objpack), Email header information (objhead), Binary Content (objbin), Text Content (objtxt), and my receiver list (reclist).

ABAP List as HTML
In this next section we will submit a program and capture its ABAP list output. We then convert this list output to HTML for inclusion as an attachment in our E-mail.

Building our Email
In this next section we will build the text body of our email.

Now we will create the packing list entry for our text body.

We already have our HTML content provided for us by the function module WWW_HTML_FROM_LISTOBJECT. We just need to create the packing list entry for this object.

In this next section we create our recipient list. I get my recipient from a select option on the screen. Now most user’s forget to supply the person’s full e-mail address and just give the SAP user id. I then take this SAP user id and call the BAPI of User Details to lookup their External E-Mail address. If I don’t find an entry in their User Master, I will create one using our standard company domain.

Finally we can make the call to our API function module:

Closing
Hopefully this little tutorial on sending E-Mail from ABAP will help users get started. If you are on release 610 or higher and are feeling left out by this weblog, just wait. Tomorrow I should post a version of this weblog for those releases. The good news is that 610 has native SMTP support built into the ICM and that sending E-mail is overall much simpler and nicer.

To report this post you need to login first.

49 Comments

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

  1. Michael Bennett
    Hi Thomas,

    In addition I think you can also use the Business Communication Interface. There are some example programs RSSOKIF1 and RSSOKIF2. In addition there is documentation on this process in the SAP Library under Basis Components -> Basis Services/Communication interfaces -> Business Workplace and services -> Generic Business tools for application developers.

    Michael

    (0) 
    1. Thomas Jung
      It would be interesting to see what method customers are using.  I had the impression that the BCI interface was not widely used by customers (I have never tried it myself).  Perhaps that perception just comes from the BCI’s late introduction followed so quickly by the BCS (Business Communication Services) in 610. 

      I plan to write another weblog today on the BCS interface.  Perhaps if you feel comfortable working with the BCI interface, you might post a similar weblog covering it.  That way all three major e-mail interfaces will be covered.

      (0) 
      1. Michael Bennett
        Ironically I have used the functions that you mention and not BCI. I only found BCI while simply searching through some of the SAP library.
        I would expect in most cases in versions <=4.6D that people would find the functions modules before they discovered BCI but that is just an opinion. So, I agree that probably not a lot of customers are using it.
        As I don’t actively use BCI I don’t I could offer much other that what is covered in the example programs already. I just thought that I would offer an alternative as much for knowledge sake.
        Good work on your weblogs.

        Michael

        (0) 
    2. Subhajit Sarkar
      Hi There,

      I had implemented the program once but the requirement was little different then i.e it needed to have the spool request attached as an attachment and sent to the respective suppliers.
      Anyways, its a very good compilation of all the aspects of it, kudos!

      Regards,
      Subhajit.

      (0) 
  2. Loffy Mathew
    Hi,
      Great piece of work. Keep it up!!!
    However when I use this function module, and I check the SOST transaction, the send date field is coming as ‘00.00. 000’. Its a bit funny.
    I have then modified my code to put in
    receivers-rec_date = sy-datum. Now the output in SOST send date is ‘01.41. 200’. Actually,the value is inserted in SOES table like this. SOST transaction is juet displaying the value. I debugged the program and found that something strange is happening in SO_NEW_DOCUMENT_ATT_SEND_API1
    go to the last line
      PERFORM TRANSFER_TAB_TO_REC TABLES REC_TABLE
                                         RECEIVERS.

    and put a breakpoint here.
    You can find that there is something strange about the way internal table receivers behaves esp. at rec_date.

    Does anyone have any clue???
    Loffy

    (0) 
  3. Anonymous
    Your article has been helpful in clearing some issues I had. I now have one more request . Do you know if we can send an email with the body in HTML using this FM ? Is that solved by setting the output format in SCOT ?

    Thanks,
    Anu

    (0) 
  4. Thomas Jung
    I got an error message on the forum when I tried to reply to your comment, so I just posted this as new.  You should be able to send HTML as the body of your message.  I have done this in 620 with the Class Based interfaces, however processing should be the same.  You don’t have to change anything in SCOT if you are controlling the call to the function module.  First make sure the content you are adding to the body object is valid HTML.  Other than that all you should have to change is in your packing list record for hte body object.  Instead of doc_type = ‘RAW’ (Plain Text), use doc_type = ‘HTM’.
    (0) 
  5. Anonymous
    Hi Thomas,

    I am back with another request. Now that I am able to send an email in Html , the request is to send te email as a multi-part email so that it displays as HTML in HTML browsers and as text in the etxt based browsers. My Java friends on the project have been doing this and now there is a request that SAP sends out hte same kind of emails also.

    Appreciate any help in this area.
    Anu

    (0) 
    1. Thomas Jung
      You got me there.  I can’t say that I have ever tried to do this.  Its not so much that I don’t know how to do this in SAP, but that I don’t know how you do this at all.

      I would suggest that you post this question in the ABAP forum.  Hopefully someone there may have ran accross this requirement before.

      (0) 
      1. Anonymous
        Sure , I will do that.

        Actually I am right now trying to understand howto do it at all … so may be that will throw some light on how we mght do it in SAP.

        Thanks for your help till now. I will come back let you know if I find a solution.

        (0) 
    2. Freddy Guerrero
      I created the html string in abap and put the content in tables objbin.

      objtxt = ‘‘.
      append objtxt.
      objtxt = ‘‘.
      append objtxt.
      objtxt = ‘Test Header‘.
      append objtxt.
      objtxt = ‘‘.
      append objtxt.
      objtxt = ‘‘.
      append objtxt.
      objtxt = ‘‘.
      append objtxt.
      objtxt = ‘‘.

      I also assigned packing_list-doc_type = ‘HTM’ but it does not work.  What else do I need to do.

      Thanks,
      Freddy

      (0) 
  6. Vincent Mozgawa
    Using call function “SO_NEW_DOCUMENT_ATT_SEND_API1” in specific program in SAP R/3, i would like to know if it is possible to send a mail on Outlook webmail box in 4.0B Version of SAP?

    Regards, Vincent

    (0) 
    1. Thomas Jung
      I’m not sure I completely understand your question.  The SO_NEW_DOCUMENT_ATT_SEND_API1 can send email to any SMTP address (as long as your SAP system is configured with the proper setup as described here). 
      (0) 
    1. Thomas Jung Post author
      JSELECT actually isn’t intented to be part of the example.  In the larger program that this sample was originally taken from, JSELECT contains the name of the Job Stream that this step is running within.  It is used in the email subject to let the user know what job generated this output.  However this example is really just focused on the conversion of the list and send of the mail. You can replace the variable JSELECT’s use with anything you want.
      (0) 
  7. p071795 K
    Hi Thomas ,

    Thats an excellent material.

    i neead some information. in  this FM
    SO_NEW_DOCUMENT_ATT_SEND_API1

    we have table packing_list in tables section . where can i find the material to find the list of document type that we can give in packing_list-doc type .

    Please let me know . my email : mysapfiles@yahoo.com

    Regards,
    Roby

    (0) 
    1. Thomas Jung Post author
      As far as I know you can give it any type of document.  You just creating a file attachment to the main document.  You give the function module the binary (or text) content – but it doesn’t need to process what type of content it is.  It just places the content of the document into the mail message. 
      (0) 
  8. Robin Ellis
    Thomas,

    I just read your Blog on Sending E-Mail from ABAP for 46D and Lower – API Interface. I found it very helpful. My problem is that I don’t see how I can control the ID of the sender of the email. When using SO_DOCUMENT_SEND_API1, you can pass the sender ID as a parameter. Our requirement is to email documents to Customers but they want the sender ID to be a generic ID, regardless of who actually runs the transcation in SAP that creates the email. This gives the Customer a much more professional looking email from us.

    Do you know how to do this?

    (0) 
    1. Suresh Datti
      AFAIK, this is only possible using the methods in CL_BCS from 47 & beyond.. that is one limitation with the SO** function modules, you might have to live with.. may be Thomas has a solution..
      ~Suresh
      (0) 
    2. Thomas Jung Post author
      Suresh is correct. The old interface does not have an easy way to control the sender.  If you are on a 6.10 or later release, then by all means switch to the BCS based Email interface.  There are many advantages, not the least of which is the ability to control the sender.

      If you are stuck with 4.6 there I can share the trick I used to use.  You can always submit your email step as a background job.  When submit a program as a background job you can specify the user it will run under and thereby control the sender id.  If the document email is already a background job, then just change the id it runs under.  Otherwise you may have to separate out your email logic into a separate program that can be submitted to background via the job scheduling APIs. 

      (0) 
  9. Kathy McGallicher
    Hello,

    I have a question about external emails.  This is quite out of my comfort zone, so I hope I can ask the question correctly.  We are unable to send emails to ISPs who perform reverse DNS authentication.  Our emails from SAP go through a Unix function called “sendmail”.  The return path in the Internet header therefore takes the name of our PS1 SAP server rather than an Exchange server.  When the reverse authentication is done, the emails are rejected as spam. 

    Have you heard of this before and do you have any suggestions on how we can resolve it?

    Thanks!

    Kathy

    (0) 
    1. Thomas Jung Post author
      I doubt this is anything that can be controlled from within ABAP.  I think you need someone who is more of a Unix sendmail or Microsoft Exchange expert.
      (0) 
  10. kavitha k
    Hi,

    I am sending some data thru email using FM :SO_DOCUMENT_SEND_API1
    This FM sends data in Excel Format. Now i need to Make the data headings in the excel sheet
    Bold. Is there any way to do. pls reply.

    Thanks ,
    kavitha

    (0) 
    1. Thomas Jung Post author
      With a text-file based Excel file there is no ability to insert formatting.  If you want to consider formatting you will probably want to switch to an XML based format.  You can find other documents on how to produce this (but it is considerably more difficult than producing a text based on – so make sure that bold headings is really worth the extra effort.)
      (0) 
  11. Alex Rombola
    I am using function ‘SO_NEW_DOCUMENT_ATT_SEND_API1’ which limits the attachments to 255 characters.  Is there another solution to sending a larger attachment from a program being run in batch?

    Thank You,
    Alex

    (0) 
    1. Thomas Jung Post author
      Actually you aren’t limited to 255 characters at all for attachements.  The attachment table simply has a line lenght of 255, which means you have to split the content over multiple lines. 

      Personally I like to build my attachment content as a binary string (XSTRING) and then use the function module SCMS_XSTRING_TO_BINARY to put the content back into the contents_hex (SOLIX) parameter of the function module.

      (0) 
      1. Alex Rombola
        Unfortunately, I do not have access to fm SCMS_XSTRING_TO_BINARY. And, I do not have the choice of splitting my lines. I must send the lines as they are (848 chars).
        (0) 
        1. Thomas Jung Post author
          Sure you have the option of splitting your lines. The line break in the attachment table doesn’t have to correspond to a line break in the actual attachment.  You are confusing the two.

          If you just build your own carriage returns into the data file and pass it as hex, then you won’t have a problem.

          As far as not having SCMS_XSTRING_TO_BINARY – what release are you on?  It must be pretty old not to have this function module.  This just means that you would have to build the binary table manually splitting the content over multiple lines of the attachement table.

          (0) 
  12. Bonny M
    I want to implement the funcationality as to whenever a job finishes either successfully or not I want to send mail to outlook stating the status of the job. I dont want to send any attachements etc. How can I achieve this?
    Thank you in advance.
    (0) 
    1. Thomas Jung Post author
      Well you would have to write this functionality as it doesn’t exist in the standard system.  Your question only remotely has anything to do with this blog as you want to use email, but the real question you are asking has to do with the job scheduling. 

      There are function modules that expose most of the job scheduling information as APIs.  You would need to write your own “job watcher” program that ran as a job itself.  It would query all the jobs that had recently finished and then send the emails.  I wrote similar applications years ago at customer sites.  It mostly involves learning to use the Job scheduling API function modules.

      (0) 
      1. Michael Bennett
        CCMS monitoring has the ability to send mails and or  SMS messages for failed jobs, we send SMS from our Production system now in the case of failed jobs.

        You might investigate CCMS functionality.

        Regards,

        Michael

        (0) 
  13. Christian Nicklas
    HI Thomas,
    it was nice to meet you at TechEd in Munich.
    I have a strange behaviour on a customer system. We implemented in our product solution the FM to send the mails with a lin to a web task to approve invoices. This worked on every system fine (when using MS-exchange).
    Now customer has lotus notes and an ERP2005 Unicode-system.
    When we send the mail with the FM always the body text is displayed as attachment in the notes client. But the really strange thing is, that when sending a mail within the business workplace, it works fine (body is displayed).
    The mails are similar when I check both in the outbox of the business workplace.

    Are there any differences when putting the Mail out (via FM or BusinessWorkplace -both should use SO_OBJECT_SEND) or settings in SCOT for RAW to create an attachment?
    Thanks in advance for any hint 😉

    (0) 
    1. Thomas Jung Post author
      I don’t have a definite answer off the top of my head.  First you might try switching from the function module to the new BCS interface (CL_BCS) since this is an ERP 6.0 system.  Second since this is a Unicode system you might check the setting in SCOT for the code page of the output.

      When you create your mail body are you attaching it as a RAW or TEXT? That could be causing some difference.  Sorry I don’t have an answer, but maybe these leads will help.

      (0) 
  14. kavitha k
    After executing the function ‘SO_DOCUMENT_REPOSITORY_MANAGER’ I get a dialog box which asks the recipients e-mailaddress.If I enter a correct mailing address everything is fine… Anyone who knows how ik can skip the dialog box en automatically fill the email address? Thanx!
    (0) 
  15. kavitha k
    After executing the function ‘SO_DOCUMENT_REPOSITORY_MANAGER’ I get a dialog box which asks the recipients e-mailaddress.If I enter a correct mailing address everything is fine… Anyone who knows how ik can skip the dialog box en automatically fill the email address? Thanx!
    (0) 
  16. Friederike Braun
    Hello,
    thank you for the excellent blog.

    My first question is: is it possible to send an e-mail with the subject longer than 50 characters (question also applies to attachment-names)?

    Second question: if the email is sent to an external address not registered as a user –> how can I find the e-mailaddress from the SOOD-dataset?

    Regards
    F.Braun

    (0) 
  17. SAURABH DESHPANDE
    Hi Thomas,

    Thanks a lot for such a nice article.
    I have requirement to send email with 1 zip file and 2 text files as an attachment.
    I successfully attached 1 zip file and text files.
    But, contents of a text file which is being attached is not in proper format. It is getting created as follows(space between each word and number of blank lines after each line) -:
    P u r c h a s e   O r d e r   :                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               F i l e s   c o n t a i n e d   i n   z i p   f i l e   a r e   :  

    Could you please suggest what is going wrong?
    My code snippet is as follows:

      IT_OBJBIN = ‘Purchase Order : ‘.
      APPEND IT_OBJBIN.
      IT_OBJBIN = ‘Files contained in zip file are :’.
      APPEND IT_OBJBIN.
      DESCRIBE TABLE IT_OBJBIN LINES BODY_NUM2.
      READ TABLE IT_OBJBIN INDEX BODY_NUM2.
      BODY_NUM2 = BODY_NUM2 – BODY_NUM.

      IT_PACKING_LIST-TRANSF_BIN = ‘X’.
      IT_PACKING_LIST-HEAD_START = 1.
      IT_PACKING_LIST-HEAD_NUM = 0.
      IT_PACKING_LIST-BODY_START = BODY_NUM + 1.
      IT_PACKING_LIST-BODY_NUM = BODY_NUM2.
      IT_PACKING_LIST-DOC_TYPE = ‘TXT’.
      IT_PACKING_LIST-OBJ_NAME = ‘Attachment2’.
      IT_PACKING_LIST-OBJ_DESCR = ‘Engg_Drawings_Details’.
      IT_PACKING_LIST-OBJ_LANGU = ‘EN’.
      IT_PACKING_LIST-DOC_SIZE  = ( BODY_NUM2 – 1 ) * 255 +
                                  STRLEN( IT_OBJBIN ).
      APPEND IT_PACKING_LIST.

    Thanks,
    Saurabh

    (0) 
  18. Shaikh Tareq

    Hi Thomas,

    I’m facing a problem in sending a URL link in the body of the Email. Since the URL exceeds 255 characters, its getting truncated at every 255 chars. and rest of the link is pushed to the next line. Is there a way to get a line of more than 255 characters in the body of the mail?

    I have tried converting the link to Hex and tried passing it through both ‘CONTENTS_HEX’ as well as ‘CONTENTS_BIN’. In each of these cases, i get the link correctly in a single line, but only as an attachment. I need it in the Main Body of the Email message.

    Any help would be highly appreciated…

    Thanks, Tareq.

    (0) 
    1. Thomas Jung Post author

      Are you just passing the link through CONTENTS_HEX and CONTENTS_BIN?  If so, of course it will be an attachment.  You can only have one body object and eveything else is an attachment.  You need to keep the URL link together with the rest of your body content and convert the entire body to binary and pass it via CONTENTS_BIN. By the way, unless you are still on release 4.6 or lower, you should really be using the CL_BCS classes instead of this older function module based approach.

      (0) 
      1. Shaikh Tareq

        Here is my actual code snippet:

          move iw_pernr to ls_doc_chngobj_name.
          ls_doc_chngobj_descr = text009.
          ls_doc_chngobj_langu = ‘E’.

          ls_objpack-transf_bin = ‘X’.
          ls_objpackhead_start = 1.
          ls_objpackhead_num   = 0.
          ls_objpackbody_start = 1.
          ls_objpackbody_num   = 1.
          ls_objpackdoc_type   = ‘BIN’.     
          append ls_objpack to li_objpack.

        *Converting the link to XSTRING

           data: lt_bin_contents type standard table of solisti1, len type i,
                   lv_xurl type xstring.
        call function ‘SCMS_STRING_TO_XSTRING’
           exporting
             text           = lw_url ” This contains the actual url
          importing
            buffer         = lv_xurl

        *Converting the XSTRING link to Binary

          call function ‘SCMS_XSTRING_TO_BINARY’
          exporting
            buffer                = lv_xurl
        *   APPEND_TO_TABLE       = ‘ ‘
        importing
           output_length         = len
          tables
            binary_tab            = lt_bin_contents

           * Send mail
          call function ‘SO_NEW_DOCUMENT_ATT_SEND_API1’
            exporting
              document_data              = ls_doc_chng
              put_in_outbox                = k_x
              commit_work                 = k_x
            tables
              packing_list               = lt_objpack
              contents_bin              = lt_bin_contents
              receivers                    = lt_reclist

        ******

        Apart from this, I have also tried the same with the method CL_BCS_CONVERT=>STRING_TO_SOLIX and passed the data through ‘CONTENTS_HEX’. Where may I have gone wrong?

        Yes Thomas, Im looking forward to switching to CL_BCS classes, but since I have this issue in an old development, I may have to persist with Function module approach. Nevertheless, if the solution is not available in the Function Module, i will have to revamp the whole code and go for Class based approach.

        (0) 
        1. Thomas Jung Post author

          > ls_objpackdoc_type   = ‘BIN’.   

          There’s your problem.  You are telling your mail client the content is binary and it therefore assumes it can’t be displayed in the body.  Change to a doc type which your mail client will like – HTM or TXT. Regardless of the fact you are sending the contents as binary you can still se the doc type to non-binary.  The doc type will be used to determine the MIME Type of the content on the client regardless of how the contents are techincally packaged.

          (0) 

Leave a Reply