MarshallSoft

SMTP/POP3/IMAP Email Engine

Library for COBOL


Programmer's Manual


(SEE4CB)


Version 5.0

June 6, 2008


This software is provided as-is.
There are no warranties, expressed or implied.



Copyright (C) 2008
All rights reserved



MarshallSoft Computing, Inc.
Post Office Box 4543
Huntsville AL 35815


Voice : 1-256-881-4630

FAX : 1-256-880-0925

email : info@marshallsoft.com

Web : www.marshallsoft.com


MARSHALLSOFT is a registered trademark of MarshallSoft Computing.




TABLE OF CONTENTS


1 Introduction
1.1 Features
1.2 Documentation Set
1.3 Example Program
1.4 Installation
1.5 Uninstalling
1.6 Pricing
1.7 Updates
2 Library Overview
2.1 Dynamic Link Libraries
2.2 Keycode
2.3 Win32 STDCALL and DECLSPEC
2.4 Error Display
3 Compiler Issues
3.1 Versions of Win32 COBOL
3.2 Compiling Fujitsu COBOL Programs
3.3 Compiling Micro Focus COBOL Programs
4 Example Programs
4.1 Connectionless Example Programs
4.2 SMTP Example Programs
4.3 POP3/IMAP Example Programs
4.4 IMAP-Only Example Programs
5 Revision History

1 Introduction

The SMTP/POP3/IMAP Email Engine for COBOL (SEE4CB) library is a powerful toolkit that allows software developers to quickly develop SMTP and POP3 email applications in COBOL. SEE4CB is a component library of functions providing direct and simple control of the SMTP (Simple Mail Transport Protocol), POP3 (Post Office 3), and IMAP 4 (Internet Message Access Protocol) protocols.

A straightforward interface allows sending and receiving email, including multiple MIME base64 and quoted-printable encoded attachments. Knowledge of Winsock and TCP/IP is not needed.

The SMTP/POP3/IMAP Email Engine for COBOL component library works with Win 32 Fujitsu COBOL and any other COBOL (such as MicroFocus COBOL) capable of calling the Windows Win32 API. SEE4CB includes numerous example programs that demonstrate SMTP and POP3 functions to help software developers easily build software applications using SEE4CB.

A Win32 DLL (Dynamic Link Library) is provided. SEE4CB runs under all versions of Windows (Windows 95, Windows 98, Windows ME, Windows 2000, Windows 2003, Windows NT, Windows XP, and Windows Vista). The SMTP/POP3/IMAP Email Engine SDK DLL (SEE32.DLL) can also be used from any language (C/C++, .NET, Visual Basic, VB. NET, VBA, Delphi, Visual FoxPro, PowerBasic, Xbase++, dBase, etc.) capable of calling the Windows API.

When comparing SMTP/POP3/IMAP Email component library against our competition, note that:

MarshallSoft also has versions of the SMTP/POP3/IMAP Email Engine library for C/C++ (SEE4C), Visual Basic (SEE4VB), Delphi (SEE4D), PowerBASIC (SEE4PB), Visual FoxPro (SEE4FP), Visual dBASE (SEE4DB), and Xbase++ (SEE4XB). All versions of the SEE library use the same DLL (SEE32.DLL). However, the examples provided for each version are written for the specified computer language.

The latest versions of SMTP/POP3/IMAP Email Engine (SEE) can be downloaded from our web site at

    http://www.marshallsoft.com/email-component-library.htm

Our goal is to provide a robust SMTP/POP3/IMAP email component library that you and your customers can depend upon. A fully functional evaluation version is available. Contact us if you have any questions.


1.1 Features

Some of the many features of SMTP/POP3/IMAP Email Engine component library are as follows:

Some of the many features of the SMTP/POP3/IMAP Email Engine component library are as follows:

Registration includes one year of free updates.

1.2 Documentation Set

The complete set of documentation consists of three manuals in three formats. This is the first manual (SEE4CB) in the set.

Each manual comes in three formats:

The SEE_4CB Programmer's Manual is the language specific (COBOL) manual. All language dependent programming issues such as compiling, compilers and example programs are discussed in this manual. Read this manual first.

The SEE User's Manual (SEE_USR) discusses email processing as well as language independent programming issues. Purchasing and licensing details are also provided.

The SEE Reference Manual (SEE_REF) contains details on each individual SEE function. A list of SEE error codes is also provided.

Use Microsoft Word or Microsoft WordPad to print the document files. The online documentation can be accessed on the SMTP/POP3/IMAP Email Engine for COBOL product page at:

    http://www.marshallsoft.com/cobol-email-component.htm



1.3 Example Program

The following example demonstrates the use of some of the SMTP/POP3/IMAP Email for COBOL component library functions:

     *> attach SEE
     CALL "seeAttach" WITH STDCALL USING
        BY VALUE     NBR-CHANS     *> number of channels
        BY VALUE     SEE-KEY-CODE  *> See KEYCODE.CBI
     END-CALL.
     *> connect to SMTP server
     DISPLAY "Calling seeConnectTo()..."
     CALL "seeConnectTo" WITH STDCALL USING
        BY VALUE     IS-ZERO       *> channel
        BY REFERENCE SMTP-SERVER   *> SMTP server
        BY REFERENCE EMAIL-FROM    *> sender's email address
        BY REFERENCE IS-ZERO       *> no Reply-To header
     END-CALL.
     *> send email
     DISPLAY "Calling seeSendEmail()..."
     CALL "seeSendEmail" WITH STDCALL USING
        BY VALUE     IS-ZERO       *> channel
        BY REFERENCE EMAIL-TO      *> recipient
        BY REFERENCE IS-ZERO       *> no CC list
        BY REFERENCE IS-ZERO       *> no BCC list
        BY REFERENCE EMAIL-SUBJ    *> email subject
        BY REFERENCE EMAIL-MSG     *> text of message
        BY REFERENCE IS-ZERO       *> no attachment
     END-CALL.
     *> close and release SEE
     CALL "seeClose" WITH STDCALL USING
        BY VALUE     IS-ZERO       *> channel
     END-CALL.
     CALL "seeRelease" WITH STDCALL
     END-CALL.

In the example program above, seeAttach is called to initialize SEE and then seeSmtpConnect is called to connect to the SMTP mail host. The SMTP server host name and your email address are required, while the "Reply-To" entry is optional.

seeSendEmail is then called, passing the addressee lists. The primary addressee is provided in the "To List". The CC ("Carbon Copy") lists additional recipients, as does the BCC (Blind Carbon Copy) list. The subject contains the email subject line. The message text is next. If it starts with the '@' symbol, it is considered the name of the file containing the email message. Lastly, the filename of any ASCII or binary attachment is specified. All fields, except the first, in seeSendEmail are optional.

After returning from seeSendEmail, the seeClose function is called to close the connection to the SMTP server. Lastly, seeRelease is called to perform SEE termination processing and release the Winsock.

1.4 Installation

  1. Before installation of SEE4CB, your COBOL compiler should already be installed on your system and tested.

  2. Unzip SEE4CB40.ZIP (or SEExxxx.ZIP where xxxx is your Customer ID) using any Windows unzip program.

  3. Run the installation program, SETUP.EXE, which will install all SEE4CB files, including copying SEE32.DLL to your Windows directory. No Windows system files are modified.

  4. Compile and run SEEVER.CBL to test your installation. The remaining example programs must be edited with your email parameters before compiling.

Note that the Windows registry is not modified.

1.5 Uninstalling

Uninstalling SEE4CB is very easy. SEE does not modify the registry.

First, run UINSTALL.BAT, which will delete SEE32.DLL from your Windows directory, typically C:\WINDOWS for Windows 95/98/Me/XP or C:\WINNT for Windows NT/2000.

Second, delete the SEE project directory created when installing SEE4CB.

1.6 Pricing

A developer license for SEE4CB can be purchased for $105. Purchasing details can be found in Section 1.5 "How to Purchase" in the SEE User's Manual (SEE_USR.HTM). Also see INVOICE.TXT provided with the evaluation version or order directly on our web site at

    http://www.marshallsoft.com/order.htm

Registration includes one year of free updates.

1.7 Updates

When a developer license is purchased, you will be sent a set of registered DLLs plus a license file (SEExxxx.LIC, where xxxx is your Customer ID). The license file can be used to update the registered DLL's for a period of one year from purchase. Updates can be downloaded from


     http://www.marshallsoft.com/oem.htm


After one year, your license must be updated if you want to be able to download updates. Your license can be updated for $30 if ordered within one year of the original purchase (or previous update). After one year, licenses can be updated for $55.

Note that the registered DLL's do not expire

Also see file UPDATES.TXT.

2 Library Overview

2.1 Dynamic Link Libraries

The SMTP/POP3/IMAP Email component library includes both Win16 and a Win32 dynamic link library (DLL). A DLL is characterized by the fact that it need not be loaded until required by an application program and that only one copy of the DLL is necessary regardless of the number of application programs that use it. Contrast this to the traditional static library that is bound to each and every application that uses it at link time.

An important advantage that DLL's have over other "popular" library formats such as VBX or OCX is that DLL's are callable by all Windows applications. Since DLL's are the building blocks of the Windows Operating System, they will not be replaced by a "newer technology".

2.2 Keycode

The SEE32.DLL has a keycode encoded within it. Your keycode is a 9 or 10 digit decimal number (unless it is 0), and will be found in the file KEYCODE.CC. The keycode for the evaluation (shareware) version is 0. You will receive a new keycode and a set of new DLL's when registering. The KEYCODE is passed to SeeAttach.

If you get an error message (value -74) when calling SeeAttach, it means that the keycode in your application does not match the keycode in the DLL. After registering, it is best to remove the evaluation version of the SEE32.DLL and SEE16.DLL from the Windows search path or delete them.

2.3 Win32 STDCALL and DECLSPEC

SEE32 is written in ANSI C and is compiled using the _stdcall and _declspec keywords. This means that SEE4CB uses the same calling conventions and file naming conventions as the Win32 API. In particular, function names are NOT decorated. There are neither leading underscores nor trailing "@size" strings added to function names.

The SEE32.DLL functions may be called by any Windows application program capable of calling the Windows API provided the proper declaration file is used.

2.4 Error Display

The error message text associated with SEE error codes can be displayed by calling seeErrorText. Each sample program contains examples of error processing.

Also see the file seeErrors.txt for a list of all Winsock and SEE error codes.


3 Compiler Issues

3.1 Versions of Win32 COBOL

The email functions in SEE32.DLL can be called from any program which is capable of calling the Windows Win32 API. In order to call the email functions, the proper syntax for calling external Windows DLL's must be used. Unfortunately, this syntax is different for each COBOL compiler.

For Fujitsu, the function interface file is SEE32.CBI. For Micro Focus, the interface file is SEE32.MFI.

3.2 Compiling Fujitsu COBOL Programs

The Fujitsu COBOL Project Manager is used to compile and link the example programs. When linking, remember to include SEE32.LIB in the list of files to link.

Alternatively, the FCL.BAT file can be used to invoke the Fujitsu compiler and linker from the command line. Be sure to copy COBOL.CBI from the Fujitsu COBOL97 directory to the directory which contains the example programs.

     FCL AUTHEN
     FCL BCAST
     FCL GETRAW
     FCL HTML
     FCL MAILER
     FCL MAILER2
     FCL READER
     FCL READER2
     FCL SEEVER
     FCL STATUS
     FCL MPARTS
     FCL FORWARD
     FCL POP3RD

3.3 Compiling Micro Focus COBOL Programs

We do not have Micro Focus COBOL, although we have many customers who use SEE4CB with it.

In order to compile for MicroFocus COBOL, examine the Micro Focus version of the SEEVER program (SEEVERMF.CBL). If you would like the complete example set for MicroFocus COBOL, send an email to support@marshallsoft.com, and we will be glad to send it to you.

3.4 Other Win32 COBOL Programming Languages.

If you develop an interface file for other COBOL languages, we would really appreciate a copy. Email the interface file, along with any example programs that you have converted, to support@marshallsoft.com.

If you are programming in another Win32 COBOL language, we may already have the necessary interface file. Let use know which COBOL you want to use.


4 Example Programs

Each example program, with the exception of SERVER.CBL, must be edited with your email parameters before compiling. For example, to change the "mail.hiwaay.net" below to "mail.mine.com", the following changes must be made:

     000360  01  SMTP-SERVER.
     000370      05  FILLER PIC X(15) VALUE "mail.hiwaay.net".
     000380      05  FILLER PIC X VALUE X'00'.

to

     000360  01  SMTP-SERVER.
     000370      05  FILLER PIC X(13) VALUE "mail.mine.net".
     000380      05  FILLER PIC X VALUE X'00'.

Note that the length was changed from 15 characters to 13 to accommodate the shorter server name.

Before writing your own programs, compile and run several of the example programs. SMTP programs send email. POP3 programs read email.

4.1 Connectionless Example Programs

The SEEVER example program does not require a connection to an SMTP server.

4.1.1 SEEVER

The first example program SEEVER displays the SEE library version number and registration string. It does not require a connection. See SEEVER.CBL for Fujitsu or SEEVERMF.CBL for MicroFocus.

Compile and run SEEVER first. It will verify that SEE32.DLL can be found at runtime and that your keycode is specified correctly.


4.2 SMTP Example Programs

There are five SMTP email example programs. SMTP programs send email.

4.2.1 AUTHEN

AUTHEN is an example program that connects to an SMTP server using SMTP Authentication. You must connect to a SMTP server which allows authentication.

AUTHEN.CBL must be edited with your email parameters before compiling.

4.2.2 BCAST

The BCAST example program emails the same message (BCAST.TXT) to a list of addresses taken from the file, BCAST.EML, containing one email address per line. Along with the SMTP server and your email address, the file containing the email message to send must be created along with another file containing the list of recipients. See EMAIL.LST for an example.

BCAST.CBL must be edited with your email parameters before compiling.

4.2.3 HTML

The HTML example program connects to an SMTP server and emails an HTML file (HTML.MAI) containing inline graphics (IMAGE1.GIF and IMAGE2.GIF). The graphics files are attached to the HTML email message.

HTML.CBL must be edited with your email parameters before compiling.

4.2.4 MAILER

The MAILER example program emails a message, including an optional MIME attachment. The MAILER.CBL program must be edited with your email parameters before compiling. Note that <> brackets are required around all email addresses.

MAILER.CBL must be edited with your email parameters before compiling.

4.2.5 MAILER2

The MAILER2 example program operates like MAILER, except that it runs in direct mode rather than indirect mode like MAILER.CBL. The primary use of direct mode is to return control to the calling application code as the email is being sent for the purpose of displaying progress. See the SMTP/POP3/IMAP User's Manual (SEE_USR) for details on direct mode.

The MAILER2.CBL example program must be edited with your email parameters before compiling.

4.2.6 ISO8859

The ISO8859 example program sends a text message and subject line that are ISO-8859-1encoded in Italian. The recipient's email client will be able to display the email message using the specified ISO character set provided that it is capable of identifying ISO-8859 MIME parts (such as MS OutLook).

4.2.7 Forward

The FORWARD example program forwards an (undecoded) email to a new recipient.


FORWARD.CBL must be edited with your email parameters before compiling.


4.3 POP3 Example Programs

There are four POP3 email example programs. These examples read email.

4.3.1 GETRAW

The GETRAW example program downloads a specified email message without decoding it. This program is used to see what the email looks like on the server.

The GETRAW.CBL program must be edited with your email parameters before compiling.

4.3.2 STATUS

The STATUS example program reads the number of email messages waiting on your POP3 email server, and displays the "DATE:", "FROM:", and "SUBJECT:" header fields from each email.

The STATUS.CBL program must be edited with your email parameters before compiling.

4.3.3 READER

The READER example program can read email, including multiple MIME attachments, from your POP3 email server, deleting each email after being read.

The READER.CBL program must be edited with your email parameters before compiling.

4.3.4 READER2

The READER2 example program operates like READER, except that it runs in direct mode rather than indirect mode like READER.CBL. The READER2.CBL program must be edited with your email parameters before compiling.

The READER2.CBL program must be edited with your email parameters before compiling.

4.3.5 POP3RD

The POP3RD example program uses the seePop3Source function to specify an (undecoded) email message file to be decoded.

The READER2.CBL program must be edited with your email parameters before compiling.

4.4 IMAP-Only Example Programs

There are two IMAP-only example programs. These examples access the IMAP server.

4.4.1 ImapFlag

The ImapFlag example program tests the manipulation of flags on the IMAP server. It reads, sets, and deletes certain flags for the specified email message on the IMAP server.

IMAP flags are:

     \Seen      Message has been read
     \Answered  Message has been answered
     \Flagged   Message is "flagged" for urgent/special attention
     \Deleted   Message is "deleted" for removal by later EXPUNGE
     \Draft     Message has not completed composition (marked as a draft).
     \Recent    Message has arrived since the previous time this mailbox was
                selected. ["\Recent" may be fetched but not stored]

4.4.2 ImapSrch

The ImapSrch example program tests IMAP search capability.

See ImapSearch.txt or http://www.marshallsoft.com/ImapSearch.htm. for a complete list of all IMAP search strings.

Example search strings as passed to seeImapSearch():

     SEEN
     SEEN NOT ANSWERED
     FLAGGED SINCE 1-Feb-2008 NOT FROM "Smith"
     LARGER 10000 NOT SEEN


5 Revision History

The SMTP/POP3/IMAP Email Engine DLL (SEE32.DLL) is written in ANSI C. All language versions of SEE (C/C++, Delphi, COBOL, PowerBASIC, FoxPro, dBase, Xbase++, COBOL, and Fortran) use the same identical DLL.

Version 1.0: June 8, 1998.

Version 2.0: [COBOL version not released]

Version 2.1: [COBOL version not released]

Version 3.0: [COBOL version not released]

Version 3.1: September 1, 1999.

Version 3.2: February 28, 2000.

Version 3.3: December 11, 2000

Version 3.4: August 14, 2001

Version 3.5: April 25, 2002

Version 3.6: May 5, 2003

Version 3.7: February 18, 2005.

Version 4.0: August 23, 2006.

Version 5.0: June 6, 2008 (Win32 Version only)

  1. seeImapConnect : Connect to IMAP server.
  2. seeImapFlags : Get, set, or delete message flags.
  3. seeImapSearch : Search for messages with specified flags.
  4. seeImapMsgNumber : Gets message numbers from buffer filled by seeImapSearch.
  5. seeImapSelectMB : Selects IMAP mailbox.
  6. seeImapDeleteMB : Delete a mailbox.
  7. seeImapCreateMB : Create a new mailbox.
  8. seeImapRenameMB : Rename mailboxes.
  9. seeImapCopyMBmail : Copy messages from selected mailbox to specified mailbox.
  10. seeImapListMB : List all available mailboxes.