Do You Speak Windows? Using Microsoft CDO to Send Email from an ACUCOBOL-GT Program



May 6, 2002
Gisle Forseth
Acucorp Developer

I know it's been a while since my last article. No, I haven't retired. Your enhancement requests and new feature work are keeping me very busy, but I just can't wait to pass along this Windows programming tip.

Some of you may remember that I implemented an e-mail client in ACUCOBOL-GT® a few years ago. (it's described in Acucorp News 2000, Issue 3, available on Acucorp's Web site.) Quite extensive, wasn't it? It required a good bit of work. Well, I am always looking around for something easier, and boy, have I found something good.

It turns out that Microsoft has a service called Microsoft Collaboration Data Objects (CDO). I am not going to go into detail about this here, but if you are interested in more information, please take a look at the Microsoft Developer Network:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdo/html/_olemsg_overview_of_cdo.asp?frame=true

These services, which are available with Microsoft Office when installed on NT computers (Windows NT, Windows 2000, and Windows XP), provide a simple method for sending e-mail messages. CDO is primarily intended for services, but in fact it is pretty handy for generic programs as well.

First, to determine if you have CDO installed on your computer, start the AXDEFGEN utility from ACUCOBOL-GT Version 5.2. You must have Version 5.2, because this is an object library. Select the Libraries tab. Press <M> to scroll the list to the items that start with the letter "M". Then scroll down until you reach the Microsoft objects and look for:

Microsoft CDO xxxx
where xxxx is:
for NTS 1.2 Library (Ver 1.2)
or
for Windows 2000 Library (Ver 1.0)

I actually have both. The AXDEFGEN dialog looks like this:

Designate the output file as "MSCDO" as shown and click OK.

Now, let's develop the application. You won't believe how easy it is. Assume an empty skeleton like this:

    IDENTIFICATION DIVISION.
    PROGRAM-ID.  HELLO.
    ENVIRONMENT DIVISION.
    SPECIAL-NAMES.
    WORKING-STORAGE SECTION.
    PROCEDURE DIVISION.
    PROGRAM-MAIN.
         DISPLAY "Hello world".
         ACCEPT OMITTED.

Now, if we add the definition file we just made in the SPECIAL-NAMES section, we get:

    IDENTIFICATION DIVISION.
    PROGRAM-ID.  HELLO.
    ENVIRONMENT DIVISION.
    SPECIAL-NAMES.
        COPY "MSCDO.DEF".
        .
    WORKING-STORAGE SECTION.
    PROCEDURE DIVISION.
    PROGRAM-MAIN.
         DISPLAY "Send email to the world".
         ACCEPT OMITTED.
         GOBACK.

The next step is to send the e-mail. Tricky? Not at all. First, add a handle to the object in WORKING-STORAGE:

77  NEW-MAIL HANDLE OF NEWMAIL OF CDONTS.

Then, add code to send the mail:

    CREATE  NEWMAIL        OF CDONTS HANDLE IN NEW-MAIL.
    MODIFY  NEW-MAIL       @Send
            ("yournamehere@somedomain.com" ,
             "recepient@somedomain.com" ,
             "Hello subject" ,
             "This is the body" ,
             0).

So, the complete code is:

    IDENTIFICATION DIVISION.
    PROGRAM-ID.  HELLO.
    ENVIRONMENT DIVISION.
    SPECIAL-NAMES.
        COPY "MSCDO.DEF".
        .
    WORKING-STORAGE SECTION.
    77  NEW-MAIL              HANDLE OF NEWMAIL OF CDONTS.
    PROCEDURE DIVISION.
    PROGRAM-MAIN.
         DISPLAY "Send email to the world".             
         CREATE  NEWMAIL       OF CDONTS HANDLE IN NEW-MAIL.
         MODIFY  NEW-MAIL      @Send
            ("yournamehere@somedomain.com" ,
             "recepient@somedomain.com" ,
             "Hello subject" ,
             "This is the body" ,
             0).
         ACCEPT OMITTED.
         GOBACK.

I told you it was easy!

For information on the availability of Microsoft CDO, look here:
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q171440

Your Session will expire in 90 minutes
Notification will be shown in:
600 seconds