SMTP/POP3/IMAP Email Engine
Library for Visual Basic
Programmer's Manual
(SEE4VB)
Version 5.0
May 1, 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.
1 Introduction
1.1 Features2 Library Overview
1.2 Documentation Set
1.3 Example Program
1.4 Installation
1.5 Uninstalling
1.6 Pricing
1.7 Updates
2.1 Dynamic Link Libraries3 Compiler Issues
2.2 Keycode
2.3 Win32 STDCALL and DECLSPEC
2.4 Using Threads
2.5 Dynamic Strings
2.6 Using VB.Net
2.7 Visual Basic for Applications (VBA)
2.8 SEE Class
2.9 PowerBuilder
2.10 Adding SEE4VB To Your Project
2.11 Error Display
3.1 Visual Basic Makefiles4 Example Programs
3.2 Compiling Programs
4.1 Connectionless Example Programs5 Revision History
4.2 SMTP Example Programs
4.3 POP3/IMAP Example Programs
4.4 IMAP-Only Example Programs
The SMTP/POP3/IMAP Email Engine for Visual Basic (SEE4VB) library is a powerful toolkit that allows software developers to quickly develop SMTP and POP3/IMAP email applications in VB or VB .NET.
The SMTP/POP3/IMAP Email Engine (SEE) is a component library of functions that uses the Windows API to provide 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 need to compile and run programs in a Visual Basic programming environment. The SMTP/POP3/IMAP Email Engine for Visual Basic component library supports and has been tested with all versions of Microsoft Visual Studio Visual Basic including VB.NET. SEE4VB can also be used with any VBA (Visual Basic for Applications) language such as Excel, Access, MS Office, etc. as well as with PowerBuilder.
SEE4VB includes numerous example programs that demonstrate SMTP and POP3/IMAP functions to help software developers easily build software applications using the SEE4VB library. All programs will compile using VB-3.0 through VB-6.0. There are also Microsoft VB.NET example programs.
SEE4VB 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, Delphi, Visual FoxPro, COBOL, Xbase++, dBase, PowerBASIC, etc.) capable of calling the Windows API.
When comparing the 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), Xbase++ (SEE4XB) and Cobol (SEE4CB). 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.
Some of the many features of the SMTP/POP3/IMAP Email Engine component library are as follows:
The complete set of documentation consists of three manuals in two formats. This is the first manual (SEE_4VB) in the set.
Each manual comes in two formats:
The SEE_4VB Programmer's Manual is the language specific (Visual Basic) manual. All language dependent programming issues such as compiling, compilers and example programs are discussed in this manual.
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 as well as 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 Visual Basic product page at:
http://www.marshallsoft.com/vb-email-component.htm
The following example demonstrates the use of some of the SMTP/POP3/IMAP Email for Visual Basic component library functions:
Dim Code As Integer
Dim Server, From As String
Dim ToList, CClist, BCClist As String
Dim Subject, Message, Attachments As String
IsNull = Chr$(0)
Server = "mail.yourisp.com
From = "my name<me@myisp.com>"
ToList = "<support@marshallsoft.com>"
CClist = Chr$(0)
BCClist = Chr$(0)
Subject = "Visual Basic Test"
Message = "Emailed from SEE4VB!"
Code = seeAttach(1, SEE_KEY_CODE) ' keycode is 0 '
If Code < 0 Then
' error calling seeAttach !
'. . .
End If
' connect to SMTP mail server
Code = seeSmtpConnect(0, Server, From, From) ' chan, server, From & Reply-To addr
If Code < 0 Then
' error calling seeSmtpConnect !
'. . .
End If
Code = seeSendEmail(0, ToList, CClist, BCClist, Subject, Message, Attachments)
If Code < 0 Then
' error calling seeSendEmail !
'. . .
End If
Code = seeClose(0)
Code = seeRelease()
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.
VB 4.0, VB5.0, and VB 6.0 project filenames end with "32.vbp", and VB.NET and Visual Studio project filenames end with "vbproj". For example,
SEEVER32.VBP --- Project file for 32-bit Visual Basic (VB_4.0,5.0,6.0)
SEEVER.VBPROJ --- Project file for VB.NET / Visual Studio
Note that the Windows registry is not modified.
Uninstalling SEE4VB 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 SEE project directory created when installing SEE4VB.
A developer license for SEE4VB can be purchased for $115. Purchasing details can be found in Section_1.4 "How to Purchase" in the SMTP/POP3/IMAP 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.
When a developer license is purchased, the developer will be sent a set of registered DLLs plus a license file (SEExxxx.LIC). 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). Between one year and three years, licenses can be updated for $55. After three years, updates are $75.
Note that the registered DLL's do not expire
Also see file UPDATES.TXT.
The SMTP/POP3/IMAP Email library SKK a Win32 [SEE32.DLL] 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".
SEE32.DLL has a keycode encoded within it. The keycode is a 9 or 10 digit decimal number (unless it is 0), and will be found in the file KEYCODE.BAS (and KEYCODE.VB). The keycode for the evaluation (shareware) version is 0. The developer will receive a new keycode and SEE32.DLL after 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 from the Windows search path or delete them.
SEE32 is written in ANSI C and is compiled using the _stdcall and _declspec keywords. This means that SEE4VB 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.
SEE4VB is thread safe (although VB itself is not always thread safe), and can be used from any Windows application capable of using threads.
The "AddressOf" operator, which was added to Visual Basic beginning in Version 5.0, is required in order to create and run Win32 threads in Visual Basic.
The necessary Win32 thread functions are declared in the file SYSTEM32.BAS.
When passing a string to a DLL function, the DLL looks for a null character to terminate the string. This null character CHR$(0) is normally present in Visual Basic strings, but can be lost if the string is modified by Visual Basic at runtime. This problem can be overcome by appending CHR$(0) to the end of strings passed to SEE functions.
The Visual Basic language uses a technique known as "garbage collection" to manage string space at runtime, and may be called internally at any time by the Visual Basic runtime, asynchronous to what you may be doing in your code.
When passing a string buffer to a DLL function into which text will be copied, it is strongly recommended that the local string be allocated immediately before use. For example, a string buffer is passed to the dllGetMessage function, which copies a text message into it. Note that SPACE$(80) is called immediately before dllGetMessage.
Dim Code As Integer
Dim Buffer As String * 80
' allocate buffer just before call to dllGetMessage
Buffer = SPACE$(80)
' copy message into 'Buffer'
Code = dllGetMessage(Buffer, 80)
' message text is now in 'Buffer'
This technique is not necessary for passing a string to a DLL function, only when passing a buffer to a DLL into which data is to be placed by the DLL function.
There are a few differences between VB 4/5/6 and VB.NET (and VS2005-VS2008) that affect writing programs that the SEE library.
Buffer = Space(128)
Length = seeErrorText(0, ErrCode, Buffer, 128)
Example VB.NET programs include:
SEEVER.VB (SEE Version Program)
STATUS.VB (Gets # emails waiting on POP3 server)
HTML.VB (Sends HTML encoded email)
The SMTP/POP3/IMAP Email component library can be used with Microsoft VBA applications such as EXCEL, ACCESS, and Microsoft Office.
Start EXCEL (or other 32-bit Office VBA program such as WORD or ACCESS), then enter design mode. Enable the "Controls Toolbox": choose "Tools" on the menu bar, then "Customize", and then check "Control Toolbox". From the control toolbox, choose and position a "Command Button". This will create code that looks like
Private Sub CommandButton1_Click()
End Sub
Replace the generated code with MODULE32.BAS. The easiest way to do this is to paste from the clipboard. Edit the 'HostName' in this code, using the name of the computer (or IP address in dotted decimal notation) where the server application (see SERVER.VBP) is running.
Exit design mode and then press the command button to start this example program.
The SEE class "seeClass" (seeClass.cls) is a Visual Basic class wrapper for making calls to SEE32.DLL. The class name for each function is the same as the DLL function, except the leading "see" is replaced by "f".
Those functions that return strings do so by use of the "String Result" property. Instantiate seeClass as any other class in Visual Basic:
Dim X As New seeClass
Also refer to the SEE4VB Reference Manual (SEE_REF), the example project "StatProj" and the file seeClass.txt.
The use of seeClass is limited to Visual Basic 5.0 and above since previous versions of Visual Basic do not support classes.
SMTP/POP3/IMAP Email Engine can also be used with Power Builder applications. Refer to PBUILDER.TXT for more information.
SEE.PBI : Power Builder declaration file.
Copy SEE32.BAS (if running VB_4.0 /5/6) or SEE32.VB (if running VB.NET) to the same directory (folder) as the application program to which you want to add SEE code. You will find these files in the APPS sub-directory (folder) created when you ran SETUP, usually C:\SEE4VB\APPS.
After the project settings are modified (see Sections 2.10.1 and 2.10.2 below), the first SEE function that must be called is seeAttach. Often, this is best done when the Visual Basic form is first loaded. For example,
Private Sub Form_Load()
Dim Code As Integer
Code = seeAttach(1, SEE_KEY_CODE)
If Code < 0 Then
MsgBox "ERROR: Cannot attach. Check SEE_KEY_CODE."
End
End If
End Sub
The last SEE function that must be called is seeRelease. This is often best done just before the application terminates. If there is an EXIT button on the form, "Code = seeRelease()" can be added. For example,
Private Sub Exit_Click()
Dim Code As Integer
Code = seeRelease()
End
End Sub
Open the existing project with "File", "Open Project". Then choose "Insert", "Module", then add SEE32.BAS (SEE16.BAS for VB_3.0) and KEYCODE.BAS to your project. If prompted to add "DAO 2.50 Object Library", choose "no".
SEE functions can now be called from your Visual Basic program.
Open the existing project with "File", "Open Project". Then choose "Project", "Add Module", then add SEE32.VB and KEYCODE.VB to your project.
SEE functions can now be called from your VB.NET program.
Open the existing project with "File", "Open Project". Then choose "Project", "Add Module", then add modules SEE32.VB and KEYCODE.VB to your project. If empty modules are created, replace the contents of these modules with the contents of the modules of the same name provided by us.
SEE functions can now be called from your Visual Studio 2005 or Visual Studio 2008 VB program.
The error message text associated with SEE error codes can be displayed by calling SeeErrorText. Each sample program contains examples of error processing.
Also refer to the file seeErrors.txt for a list of all Winsock and SEE error codes.
The SMTP/POP3/IMAP Email Engine for Visual Basic component library supports and has been tested with all versions of Microsoft Visual Basic (VB 4, VB 5, VB 6, VB.NET, and Visual Studio). The SETUP installation program will copy the Lib's and DLL to the Windows directory. Refer to Section 1.4 "Installation".
The first Visual Basic for Windows (VB Version 3.0) uses a text file known as a "Visual Basic makefile" (.MAK) to list all the file components necessary to compile a program. Beginning with Visual Basic Version 4.0, the "Visual Basic Project file" (.VBP) was added. Both formats are "project files".
Project files are provided for all examples. Project files for VB 4/5/6 end with the extension ".vbp" and end with ".vbproj" for Visual Studio (and VB.NET).
The example programs can be compiled from the Visual Basic development environment using the provided Visual Basic project files. Choose "File", then "Open Project" from the main VB menu.
After opening a project, VB 5.0 (and VB 6.0) users can save the project files in the VB 5.0 (or VB 6.0) format. When saving the example programs in VB version 5.0 or VB 6.0 format, answer "no" if asked to add the "Microsoft DAO v2.5 library".
Compile and run SEEVER32 as the first example to check your installation. SEEVER does not require a TCP/IP connection.
Multiple Visual Basic example programs are included in SMTP/POP3/IMAP Email Engine for Visual Basic (SEE4VB). Examples for both Visual Basic 4/5/6 as and Visual Studio (and VB.NET) are included. There is also an example program (StatProj) that uses the VB class "seeClass".
Each example program comes with a VB project file.
Before writing your own programs, compile and run several of the example programs.
Several example programs do not require a connection to a server.
The SEEVER example program displays the SEE library version number and registration string. . Its purpose is to display the SEE version, build, and registration string as well as to verify that SEE32.DLL is being found and loaded by Windows.
Open project SEEVER32.VBP or SEEVER.VBPROJ (Visual Studio or VB.NET).
The CODETEST example program demonstrates how to use seeEncodeBuffer and seeDecodeBuffer, which encodes and decodes several test strings using BASE64. The CODETEST example program also demonstrates the use of seeEncodeUTF8 and seeDecodeUTF8.
Open project CODETEST.VBP.
There are eleven SMTP email example programs. SMTP programs send email using an SMTP server.
AUTHEN is an example program that connects to an SMTP (ESMTP) server using SMTP Authentication. You must connect to an SMTP server that allows authentication.
Open project AUTHEN32.VBP.
AUTO ("auto-responder") uses two channels to read email on the POP3 server and at the same time automatically responds to all new email using the SMTP server. Edit your TCP/IP parameters in AUTO32.FRM (line 73) before compiling.
Open project AUTO32.VBP.
BCAST (Broadcast) emails the same message to each recipient from a file of email addresses. 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. See BCAST.EML for an example.
Open project BCAST32.VBP.
HELLO emails a short message. You must edit HELLO32.FRM with your server and email address before compiling.
Open project HELLO32.VBP.
The HTML example program connects to an SMTP server and emails an HTML file containing inline embedded graphics. The graphics files are attached to the HTML email message.
Open project HTML32.VBP or HTML.VBPROJ (VB.NET).
MAILER emails a message, including optional MIME attachments. All required parameters are input using a dialog box at runtime. Open project MAILER32.VBP.
Note that <> brackets are required around the email address.
VERUSR (Verify User) connects to a specified SMTP server and requests verification of the user.
Due to security concerns, some SMTP servers will not honor a "verify user" request. A user that does not verify does NOT necessarily mean that the email address is not good.
Open VERUSR32.VBP.
The ISO8859 example program sends a text message and subject line that is 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 Microsoft OutLook).
Open project ISO8859.VBP.
The MParts example program sends a multipart MIME email in which the Content-Type headers for each attachment are specified by the programmer.
The two attachment types specified in this example are a sound file (.wav) and a PDF file (.pdf).
Open project MPARTS.VBP.
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 Microsoft OutLook).
Open project GB2312.VBP.
The FORWARD example program forwards an email message to a new recipient. Only undecoded email messages can be forwarded.
Open project FORWARD.VBP.
There are six POP3/IMAP email example programs. These examples read email using the POP3 (or IMAP) server.
AUTO ("auto-responder") uses two channels concurrently to read email on the POP3 server and at the same time automatically respond to all new email using the SMTP server. Edit your TCP/IP parameters in AUTO32.FRM (line 73) before compiling.
Open project AUTO32.VBP.
GETRAW is a Win32 program that downloads a specified email message without decoding it. This is used to see what the email looks like on the server. Also see the READER example program, which can also download email without decoding it.
All required parameters are coded inside GETRAW32.FRM (line 67) and must be edited before compiling.
Open GETRAW32.VBP.
READER can read email, including multiple MIME attachments, from your POP3 server, optionally deleting each email after being read. READER can also download email without decoding. All required parameters are input at runtime.
Open READER32.VBP.
STATPROJ gets the number of email messages waiting on your POP3 server.
The "StatProj" example uses the Visual Basic class seeClass.cls. For more details on the seeClass, refer to Section 2.8 "SEE4VB Class".
All required parameters are input at runtime. Open STATPROJ.VBP from Visual Basic 5.0 (or above).
STATUS reads the number of email messages waiting on your POP3 server, and displays the "DATE:", "FROM:", and "SUBJECT:" header fields from each email. All required parameters are input at runtime.
Open project STATUS32. VBP, or STATUS.VBPROJ.
The Pop3Read example program uses the seePop3Source function to specify an (undecoded) email message file to be read and decoded.
Open project POP3READ.VBP.
There are three IMAP-only email example programs. These examples access the IMAP server.
The ImapFlagsT 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]
Open project ImapFlagsT.vbp (VB 4/5/6)
Open project ImapFlagsT.vbproc (Visual Studio or VB.NET)
The ImapSearch 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
Open project ImapSearch.vbp (VB 4/5/6)
Open project ImapSearch.vbproc (Visual Studio or VB.NET)
The ImapMBtest example program tests IMAP functions seeImapConnect, seeImapListMB, seeImapDeleteMB, seeImapCreateMB, and seeImapSelectMB.
Open project ImapMBtest.vbp (VB 4/5/6)
Open project ImapMBtest.vbproc (Visual Studio or VB.NET)
The SMTP/POP3/IMAP Email Engine DLLs (SEE16.DLL and SEE32.DLL) are written in ANSI C. All language versions of SEE (C/C++, Delphi, Visual Basic, PowerBASIC, FoxPro, Delphi, Xbase++, COBOL, and Fortran) use the same identical DLLs.
Version 1.0: June 22, 1998.
Version 2.0: September 28, 1998.
Version 2.1: November 28, 1998.
Version 3.0: April 12, 1999.
Version 3.1: July 16, 1999.
Version 3.2: January 17, 2000.
Version 3.3: October 3, 2000
Version 3.4: July 17, 2001
Version 3.5: March 12, 2002
Version 3.6: April 1, 2003
Version 3.7: January 21, 2005.
Version 4.0: July 3, 2006.
Version 5.0: May 1, 2008 (Win32 Version only)