Using Microsoft Access Basic to Send Mail Messages

Using the different methods above, you allow Microsoft Access to set up the message, package up the attachment and call the MAPI interface to send out the message. Extending this functionality requires the use of the Microsoft Windows operating system API capabilities in Microsoft Access. There are calls that you make to MAPI, passing in informational structures, to initiate the mail process.

There are three important structures that you'll be using to send and receive messages. These are:

w MAPIMessage

w MAPIRecip

w MAPIFile

These are outlined next.

The MAPIMessage Structure

When you create a message, you fill out a structure that will be passed to the MAPI routines. This structure defines the different aspects of the mail message, what it contains and how it is handled.


Type MAPIMessage
    Reserved As Long
    Subject As String
    NoteText As String
    MessageType As String
    DateReceived As String
    ConversationID As String
    Flags As Long
    RecipCount As Long
    FileCount As Long
End Type

The MAPI message structure defines more than just the visible components of the message. It also provides information about the MessageType and the number of recipients and attachments, indicated by FileCount.

Message Types

MessageTypes are a means of identifying classes of messages. Message types are made up of three distinct portions. The format of a message class can be seen with this example Schedule Plus meeting request message:


IPM.Microsoft Schedule.MtgReq

This message class is registered in your MSMAIL.INI file, identifying it to the MSMail client. The client software then knows how to work with this message class, and that it is to be treated differently from other message classes on your system.

The prefix, the first three characters of the message class, can be one of the following types:

w Inter-Personal Messages (IPM) - these messages are the messages that show up in the current MSMail 3.x client software. These messages are the typical messages that include schedule plus messages, mail messages created with the MSMail 3.x client, etc.

w Inter-Process Communication (IPC) - these messages are designed to be sent from one process to another. An example of this might be a message created by your Microsoft Access system that updates another Microsoft Access system. The update can be sent as an IPC message and retrieved by the remote system. IPC messages do not show up in the MSMail 3.x client. You have to retrieve IPC messages by message class.

It's important to understand that both message types are delivered using the MAPI subsystem. The prefix merely specifies how the message will be managed by the recipient's system.

When you create a message class, use the second section, "Microsoft Schedule" above, to indicate the broad classification of the type of message. For example, if you're creating a system to send Financial Reports and there are several different types of messages, a message class might be:


IPM.Financial Reports.Updates
IPM.Financial Reports.Stocks
IPM.Financial Reports.Bonds
IPM.Financial Reports.Annual

The third section should indicate the specific type of message as it relates to the general classification. In other words, the final portion of the message class is used to specify the most detailed description of the message contents or purpose.

The MAPIRecip Structure

When you establish a message, you must indicate where the message is headed. You indicate the intended recipients of the message by filling out the MAPIRecip structure.


Type MAPIRecip
    Reserved As Long
    RecipClass As Long
    Name As String
    Address As String
    EIDSize As Long
    EntryID As String
End Type

All recipients are defined in this structure whether they be primary, CC or BCC recipients. You indicate the type of recipient by setting up the RecipClass property. The property has the following values:

MAPIRecip.RecipClass Settings

Setting

Description

MAPI_ORIG

This setting, a value of 0, specifies the recipient as the originator. You'll refer to recipients of this type when you are reading messages that have been received at your workstation.

MAPI_TO

This setting, a value of 1, specifies that this recipient is a primary, non CC or BCC recipient.

MAPI_CC

This setting has a value of 2 and specifies that the recipient is a carbon copy, or CC, recipient for the message.

MAPI_BCC

This setting's value is 3. It sets up the recipient as a blind carbon copy, or BCC, recipient of the message.


You'll be passing an array of the MAPIRecip structure type to the MAPI layer when you send a message. Set the total number of recipients in the MAPIMessage structure RecipCount property, telling the MAPI interface how many instances of the MAPIRecip structure will be forthcoming.

The MAPIFile Structure

When you attach files to a mail message, you provide information about the file in the MAPIFile structure. This structure includes information about the location of the file, the type of file, etc. In addition, it includes information about where in the message the file will be located.


Type MAPIFile
    Reserved As Long
    Flags As Long
    Position As Long
    PathName As String
    FileName As String
    FileType As String
End Type

An important note here is that you must have at least one character in your message before you can successfully attach a file to the message. If you're only sending the attachment, be sure to set the NoteText to at least a space, " " prior to attaching your file.

You add one MAPIFile structure for each item you are attaching. In the MAPIMessage structure, you define how many attachments are to be included by incrementing the FileCount property.