MarshallSoft

SMTP/POP3/IMAP Email Engine

Library for Xbase++


Programmer's Manual


(SEE4XB)


Version 5.0

May 30, 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

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
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
2.5 Adding SEE4XB to a Project
3 Compiler Issues
3.1 INCLUDE Files
3.2 Compiling and Linking Programs
3.3 Xbase++ Compiler
4 Example Programs
4.1 Connectionless Example Programs
4.2 SMTP Email Example Programs
4.3 POP3/IMAP Email Example Programs
4.4 IMAP-Only Example Programs
5 Revision History

1 Introduction

The SMTP/POP3/IMAP Email Engine for Xbase++ (SEE4XB) library is a powerful toolkit that allows software developers to quickly develop SMTP and POP3 email applications in Alaska Xbase++. The SMTP/POP3/IMAP Email Engine (SEE) 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 Programmer's Manual provides information needed to compile and run programs in an Xbase++ programming environment.

The SMTP/POP3/IMAP Email Engine for Xbase++ component library supports and has been tested with Alaska Xbase++ version v1.3 through and Xbase++ v1.9. SEE4XB includes numerous example programs that demonstrate SMTP and POP3/IMAP functions to help software developers easily build software applications using the SEE4XB library.

SEE4XB 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, COBOL, PowerBASIC, 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), Delphi (SEE4D), PowerBASIC (SEE4PB), Visual FoxPro (SEE4FP), Visual dBASE (SEE4DB), and Visual Basic (SEE4VB). All versions of the SEE library use the same DLL (SEE32.DLL). However, the examples provided for each version are written for the specified programming 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 the SMTP/POP3/IMAP Email Engine component library are as follows:

Royalty free distribution (no run-time fees) with your compiled application


1.2 Documentation

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

Each manual comes in two formats:

The SEE_4XB Programmer's Manual is the language specific (Xbase++) 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 license details are also provided.

The SEE Reference Manual (SEE_REF) contains details on each individual SEE function as well as SEE error codes.

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 Xbase++ product page at:

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



1.3 Example Program

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

     #INCLUDE "DLL.CH"
     #INCLUDE "KEYCODE.CH"
     #INCLUDE "SEE32.CH"
   
     *** PROGRAMMER: Edit these strings [use host name or IP address for server] ***
     SmtpServer = "10.0.0.1"
     SmtpFrom = "<mike@10.0.0.1>"
     SmtpReply = chr(0)
     SmtpTo   = "<mike@10.0.0.1>"
     DiagFile = ".\HELLO.LOG"
     *** END PROGRAMMER ***
   
     ? "HELLO 5/30/2008"
     Code = seeAttach(1, SEE_KEY_CODE)
     if Code < 0
       ? "Cannot attach SEE"
       return
     endif
     Code = seeStringParam(0, SEE_LOG_FILE, @DiagFile)
     *** set maximum connect wait to 20 seconds
     Code = seeIntegerParam(0, SEE_CONNECT_WAIT, 20000)
     *** connect to SMTP server
     ? "Connecting to " + SmtpServer
     Code = seeSmtpConnect(0, @SmtpServer, @SmtpFrom, @SmtpReply)
     if Code < 0
       Temp = SPACE(128)
       Code = seeErrorText(0,Code,@Temp,128)
       ? Left(Temp,Code)
     else
       *** send email message
       ? "Sending email to " + SmtpTo
       Code = seeSendEmail(0,SmtpTo,"","","Hello from Xbase++","Hello from Xbase++","")
       if Code < 0
         Temp = SPACE(128)
         Code = seeErrorText(0,Code,@Temp,128)
         ? Left(Temp,Code)
       else
         ? "Email has been sent."
       endif
     endif
     ? "Done."
     Code = seeClose(0)
     Code = seeRelease()
     return

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 SEE4XB, an Xbase++ compiler (any version) should already be installed on your system and tested.

  2. Unzip SEE4XB50.ZIP (or SEExxxxx.ZIP where xxxxx is your Customer ID) using any Windows unzip program.

  3. Run the installation program SETUP.EXE that will install all SEE4XB files and copy SEE32.DLL to the Windows directory. No Windows system files are modified.

  4. You are ready to compile and run! For a quick start, load the project file SEEVER.PRG.

Note that the install process does not modify the Windows registry.

1.5 Uninstalling

Uninstalling SEE4XB is very easy. SEE does not modify the registry or any Windows system files.

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

Second, delete the SEE4XB project directory created when installing SEE4XB.

1.6 Pricing

A developer license for SEE4XB can be purchased for $115. Purchasing details can be found in Section_1.4 "How to Purchase" in the SEE User's Manual (SEE_USR.HTM). Also refer to 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 and technical support.

1.7 Updates

When a developer license is purchased, the developer will be sent a registered DLLs plus a license file (SEExxxxx.LIC, where xxxxx is your Customer ID). The license file can be used to update the registered DLL 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, although the registered DLL never expires. Your license can be updated for $30 if ordered within one year of the original purchase (or previous update). Between one year and three years, licenses can be updated for $55. After one year, licenses can be updated for $75.

As noted above, 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 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.CH. The keycode for the evaluation version is 0. You will receive a new keycode and a new SEE32.DLL after purchasing or updating a developer license. The KEYCODE must be 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 and before installing the registered version, it is best to remove the evaluation version of the SEE32.DLL from the Windows search path or delete it.

2.3 Win32 STDCALL and DECLSPEC

SEE32 is written in ANSI C and is compiled using the _stdcall and _declspec keywords. This means that SEE4XB 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.

Any Windows application program may call the SEE32 library provided that 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.

2.5 Adding SEE4XB to a Project

It is straightforward to add SEE to both console mode and GUI Xbase++ programs.  First, add
   
     #INCLUDE "KEYCODE.CH"
     #INCLUDE "SEE32.CH"
   
after any other $INCLUDE statements in the Xbase++ program.

Then add
   
     nCode = seeAttach(1 SEE_KEY_CODE)
     If nCode < 0 Then
       ? "Cannot attach SEE"
       return
     endif
   
as the first executed SEE function.

The keycode (contained in KEYCODE.CH) is 0 for the evaluation version and is a 9-digit number for the purchased version. Rather than include KEYCODE.CH as shown above, the keycode can be pasted directly into the call to seeAttach.

Lastly, link your program with SEE32.LIB. Refer to the example programs in the SEE4XB/APPS subdirectory.


3 Compiler Issues

SEE4XB has been compiled and tested with Xbase++ version v1.3 through and Xbase++ v1.9. The SETUP installation program will copy the Lib's and SEE32.DLL to the Windows directory. Refer to Section 1.4 "Installation".

3.1 INCLUDE Files

All example programs include two files: KEYCODE.CH and SEE32.CH. The file SEE32.CH contains all the necessary constants and function declarations for SEE4XB, while the file KEYCODE.CH contains your keycode (license key), as discussed in Section 2.2.

The Alaska Xbase++ include file DLL.CH is also required. For example,

     #INCLUDE "DLL.CH"
     #INCLUDE "KEYCODE.CH"
     #INCLUDE "SEE32.CH"

The above files can be copied to the Xbase++ INCLUDE directory (where Xbase++ can find it) if so desired.

Note that each function is declared with the prefix character of 'X'

3.2 Compiling and Linking Programs

Before compiling any of the example programs, edit each program with your TCP/IP email parameters, as shown in the example program in Section 1.3 above. Server names can be IP addresses (in decimal dot notation) or the host name. Email addresses must be enclosed in angle brackets.

More details on each of the example programs are provided in Section 4.0, "Example Programs.

To compile and link console mode programs, such as STATUS.PRG, use

     XPP STATUS.PRG
     ALINK STATUS.OBJ SEE32.LIB

To compile and link windows GUI programs, such as FROM.PRG, use

     XPP FROM.PRG
     ALINK /SUBSYSTEM:WINDOWS FROM.OBJ SEE32.LIB

3.3 Xbase++ Compiler

If you don't have the Alaska Software Xbase++ compiler, you can find it on the web at

     http://www.alaska-software.com
   

4 Example Programs

Each example program, with the exception of SEEVER.PRG and CODETEST.PRG, must be edited with your TCP/IP email parameters before compiling. Refer to the SMTP/POP3/IMAP Email User's Manual (SEE_USR) for details.

Refer to Section 3.2 above for information on compiling and linking the example programs.

Be sure to edit the example programs with your email parameters before compiling. Before writing your own programs, compile and run several of the example programs.

4.1 Connectionless Example Programs

Two SEE4XB example programs do not require a connection to a server.

4.1.1 SEEVER

This simple program displays the SEE library version number and registration string taken from SEE32.DLL. Its purpose is display the SEE version, build, and registration string as well as to verify that SEE32 is being found and loaded by Windows. The SEEVER program does not connect to your LAN (or the Internet).

This is the first program that you should compile and run.

4.1.2 CODETEST

The CODETEST example program demonstrates how to use seeEncodeBuffer and seeDecodeBuffer, which BASE64 encodes and decodes several test strings. The CODETEST example program also demonstrates the use of seeEncodeUTF8 and seeDecodeUTF8.


4.2 SMTP Email Example Programs

There are eleven SMTP email example programs. SMTP programs send email using an SMTP server.

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 that allows authentication.

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

4.2.2 AUTO

AUTO ("auto-responder") uses two channels concurrently to automatically respond to all new email. AUTO will read (but not delete) all email on your server and reply to each that "your email was received".

AUTO.PRG must be edited with your email parameters before compiling.

4.2.3 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 your SMTP server and your email address, you must create the file containing the email message to send, and create another file containing the list of recipients.

4.2.4 GB2312

The GB2312 example program sends a text message that is GB2312 (simplified Chinese) encoded. The recipient's email client will be able to display the email message using the specified GB2312 character set provided that it is capable of identifying GB2312 MIME parts (such as MS OutLook).

4.2.5 HELLO

The HELLO program emails a short message. HELLO.PRG must be edited with your email parameters before compiling. Compare with the MAILER example program.

4.2.6 HTML

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

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

4.2.7 ISO8859

The ISO8859 example program sends a text message and subject line that are ISO-8859 encoded. 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.8 MAILER

The MAILER example program emails a message, including an optional MIME attachment. MAILER.PRG must be edited with your email parameters before compiling.


4.2.9 MAILER2

The MAILER2 example program operates the same as the MAILER program, except that it uses the "indirect" method. MAILER2.PRG must be edited with your email parameters before compiling.

4.2.10 Mparts

The MParts example program sends a multipart MIME email in which the programmer specifies the Content-Type headers for each attachment.

The two attachment types specified in this example are a sound file (.wav) and of PDF file (.pdf).

4.2.11 Forward

The FORWARD example program forwards an email message to a new recipient. Only undecoded email messages can be forwarded.

Undecoded email message can be downloaded using the GETRAW and READER example programs.


4.3 POP3 Email Example Programs

There are eight POP3/IMAP example programs. These examples read email using a POP3 or IMAP server. Each example program, except for the FROM program, must be edited with your email parameters before compiling.

4.3.1 AUTO

AUTO ("auto-responder") uses two channels concurrently to automatically respond to all new email. AUTO will read (but not delete) all email on your server and reply to each that "your email was received".

AUTO.PRG must be edited with your email parameters before compiling.

4.3.2 FROM

The FROM program operates like the STATUS example program, except that it uses an Xbase++ form to enter the POP3 server, user, and password.

The FROM program must be linked as a GUI (rather than console mode) application:

     XPP FROM.PRG
     ALINK /SUBSYSTEM:WINDOWS FROM.OBJ SEE32.LIB

4.3.3 GETRAW

GETRAW is an example program that downloads a specified email message without decoding it (in "raw" format). This is used to see what the email looks like on the server. GETRAW.PRG must be edited with your email parameters before compiling.

4.3.4 READER

READER can read email, including multiple MIME attachments, from your POP3 server, deleting each email after being read. READER.PRG must be edited with your email parameters before compiling.

4.3.5 READER2

The READER2 example program operates the same as the READER program, except that it uses the "indirect" method. READER2.PRG must be edited with your email parameters before compiling.

4.3.6 STATUS

STATUS reads the number of email messages waiting on your POP3 server, and displays the "DATE:", "FROM:", and "SUBJECT:" header fields from each email. STATUS.PRG must be edited with your email parameters before compiling.

4.3.7 STATUS2

The STATUS2 example program operates the same as the STATUS program, except that it uses the "indirect" method. STATUS2.PRG must be edited with your email parameters before compiling.

4.3.8 Pop3Rd

The Pop3Read example program uses the seePop3Source function to specify an (undecoded) email message file to be read and decoded. There is no connection to any server.

Undecoded email message can be downloaded using the GETRAW and READER example programs.


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 (IMAP Flags Test) 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 (IMAP Search) 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 programming language versions of SEE (C/C++, Visual Basic, PowerBASIC, Delphi, Visual FoxPro, Visual dBase, Xbase++, COBOL, and Fortran) use the same identical DLL.

Version 3.2: February 21, 2000.

Version 3.3: November 20, 2000

Version 3.4: August 14, 2001

Version 3.5: April 10, 2002

Version 3.6: April 28, 2003

Version 3.7: February 10, 2005.

Version 4.0: July 24, 2006.

Version 5.0: May 30, 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.