📄 ch6.htm
字号:
<html>
<head>
<title>Chapter 6 -- Creating MAPI-Aware Applications</title>
<meta NAME="GENERATOR" CONTENT="Microsoft FrontPage 3.0">
</head>
<body TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A8B" ALINK="#CE2910">
<!-- Spidersoft WebZIP Ad Banner Insert -->
<!-- End of Spidersoft WebZIP Ad Banner Insert-->
<h1><font COLOR="#FF0000">Chapter 6</font></h1>
<h1><b><font SIZE="5" COLOR="#FF0000">Creating MAPI-Aware Applications</font></b> </h1>
<hr WIDTH="100%">
<h3 ALIGN="CENTER"><font SIZE="+2" COLOR="#000000">CONTENTS<a NAME="CONTENTS"></a> </font></h3>
<ul>
<li><a HREF="#TheSimpleMAPIAPICalls">The Simple MAPI API Calls</a> <ul>
<li><a HREF="#TheUserDefinedTypes">The User-Defined Types</a> </li>
<li><a HREF="#TheAPIFunctions">The API Functions</a> </li>
</ul>
</li>
<li><a HREF="#CreatingMailAwareApplications">Creating Mail-Aware Applications</a> <ul>
<li><a HREF="#CreatingQIKMAILXLSwithExcel">Creating QIKMAIL.XLS with Excel</a> </li>
<li><a HREF="#AddingMAPIServicestoExistingVisual">Adding MAPI Services to Existing Visual
Basic 4.0 Programs</a> </li>
</ul>
</li>
<li><a HREF="#Summary">Summary</a> </li>
</ul>
<hr>
<p>The most basic MAPI service is the ability to provide a send feature to a program.
Almost all Windows programs have a print feature to send output to a print device. The
send feature works basically the same way. It provides the user a way to send output to
some other e-mail address. Adding this most basic form of MAPI service to your Windows
applications makes it "MAPI-aware." MAPI-aware applications do not have e-mail
services as a basic part of their functionality (that is, an e-mail client) but provide it
as an added feature. For example, most office suite applications (word processing,
spreadsheet, and so on) provide a send feature on the main menu of all their programs.
Basically, whatever documents you can create with the program can be sent to other
locations using the mail services available on the network. </p>
<p>In this chapter, you'll learn how to make your programs MAPI-aware using the Simple
MAPI API call set. This API set provides very easy, very quick access to the most needed
MAPI services. Another advantage of using the API set is that it is available to any
program that supports DLL calls. This means it is quite easy to add MAPI services to most
any Windows application. </p>
<p>In the first half of this chapter, you'll get a quick overview of the API calls
themselves. You'll learn about the eleven API calls and three user-defined types that
comprise the Simple MAPI interface, and you'll build a set of examples that illustrate the
use of Simple MAPI services. </p>
<p>In the second half of the chapter, you'll create some real-world examples of Windows
applications that have MAPI-aware features. You'll create a quick spreadsheet routine that
can send its results using MAPI. You'll also modify an existing Visual Basic 4.0 program
to add MAPI capabilities. </p>
<p>When you complete this chapter, you'll have a good understanding of the Microsoft MAPI
API calls. You will also be able to design and build applications that can use the MAPI
interface to provide mail services from within your Visual Basic programs. </p>
<h2><a NAME="TheSimpleMAPIAPICalls"><font SIZE="5" COLOR="#FF0000">The Simple MAPI API
Calls</font></a></h2>
<p>The Simple MAPI (SMAPI) calls allow you to add MAPI services to virtually any Windows
program. While these calls offer only the smallest set of MAPI services, they are still
quite useful. In the next few sections, you'll learn about the three user-defined
structures needed to provide MAPI via the API calls, and you'll experiment with each of
the API calls themselves. </p>
<div align="center"><center>
<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
<tr>
<td><b>Note</b></td>
</tr>
<tr>
<td><blockquote>
<p>All the SMAPI services for Visual Basic and VBA applications are provided through the
dynamic link library (DLL) called <tt><font FACE="Courier">VBAMAP32.DLL</font></tt> (or <tt><font
FACE="Courier">VBAMAPI.DLL</font></tt> for 16-bit plat-forms). If you do not already have
this DLL on your system, you can find it on the CD-ROM that ships with this book. </p>
</blockquote>
</td>
</tr>
</table>
</center></div>
<p>Before you begin this part of the chapter, start Visual Basic 4.0 and begin a new
project. Locate the <tt><font FACE="Courier">VBAMAP32.BAS</font></tt> module in the <tt><font
FACE="Courier">Chap06</font></tt> folder and add that module to your project. This has all
the API calls and structures defined along with several constants and a helper error
function. </p>
<div align="center"><center>
<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
<tr>
<td><b>Note</b></td>
</tr>
<tr>
<td><blockquote>
<p>Throughout this chapter, you'll use the 32-bit version of the SMAPI set. A 16-bit
version of the SMAPI calls can also be used. You'll find the 16-bit version of the API
calls in the <tt><font FACE="Courier">VBAMAP16.BAS</font></tt> module on the CD-ROM. </p>
</blockquote>
</td>
</tr>
</table>
</center></div>
<h3><a NAME="TheUserDefinedTypes">The User-Defined Types</a></h3>
<p>Simple MAPI defines three structures for passing information
<ul>
<li><i>MAPIMessage</i>-Contains all the information about a message packet, including
originator, subject, text, recipients, and attachments. </li>
<li><i>MAPIRecip</i>-Contains all the information about a message recipient, including name,
address type, full address, and unique entry ID. </li>
<li><i>MAPIFile</i>-Contains all the information about an attached file, including display
name, operating system name, and position in the message packet. </li>
</ul>
<h4><tt><font FACE="Courier">MAPIMessage</font></tt></h4>
<p>The <tt><font FACE="Courier">MAPIMessage</font></tt> structure is used to hold all the
vital information about a message packet. You will use this structure to pass message data
from your programs to the DLL and back. Table 6.1 shows the structure of the <tt><font
FACE="Courier">MAPIMessage</font></tt> along with short descriptions for each element.<br>
</p>
<p align="center"><b>Table 6.1. The <tt><font FACE="Courier">MAPIMessage</font></tt>
structure.</b> </p>
<div align="center"><center>
<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
<tr>
<td><i>Field</i></td>
<td WIDTH="84"><i>Type</i></td>
<td WIDTH="391"><i>Description</i></td>
</tr>
<tr>
<td WIDTH="115"><tt><font FACE="Courier">Reserved</font></tt> </td>
<td WIDTH="84">Long</td>
<td WIDTH="391">Reserved for future use. This field must be 0. </td>
</tr>
<tr>
<td WIDTH="115"><tt><font FACE="Courier">Subject</font></tt> </td>
<td WIDTH="84">String</td>
<td WIDTH="391">The subject text, limited to 256 characters or fewer. (Messages saved
using <tt><font FACE="Courier">MAPISaveMail</font></tt> are not limited to 256
characters.) An empty string indicates no subject text. </td>
</tr>
<tr>
<td WIDTH="115"><tt><font FACE="Courier">NoteText</font></tt> </td>
<td WIDTH="84">String</td>
<td WIDTH="391">A string containing text in the message. An empty string indicates no
text. For inbound messages, each paragraph is terminated with a carriage return-line feed
pair (0x0d0a). For outbound messages, paragraphs can be delimited with a carriage return,
a line feed, or a carriage return-line feed pair (0x0d, 0x0a, or 0x0d0a, respectively). </td>
</tr>
<tr>
<td WIDTH="115"><tt><font FACE="Courier">MessageType</font></tt> </td>
<td WIDTH="84">String</td>
<td WIDTH="391">A message type string used by applications other than interpersonal
electronic mail. An empty string indicates an interpersonal message (IPM) type. </td>
</tr>
<tr>
<td WIDTH="115"><tt><font FACE="Courier">DateReceived</font></tt> </td>
<td WIDTH="84">String</td>
<td WIDTH="391">A string indicating the date a message is received. The format is
YYYY/MM/DD HH:MM; hours are measured on a 24-hour clock. </td>
</tr>
<tr>
<td WIDTH="115"><tt><font FACE="Courier">ConversationID</font></tt> </td>
<td WIDTH="84">String</td>
<td WIDTH="391">A string indicating the conversation thread ID to which this message
belongs. </td>
</tr>
<tr>
<td WIDTH="115"><tt><font FACE="Courier">Flags</font></tt></td>
<td WIDTH="84">Long</td>
<td WIDTH="391">A bitmask of flags. Unused flags are reserved. Unused flags must be 0 for
outbound messages and are ignored for inbound messages. The following flags are defined: <br>
<tt><font FACE="Courier">MAPI_RECEIPT_REQUESTED<br>
MAPI_SENT<br>
MAPI_UNREAD</font></tt> </td>
</tr>
<tr>
<td WIDTH="115"><tt><font FACE="Courier">RecipCount</font></tt> </td>
<td WIDTH="84">Long</td>
<td WIDTH="391">A count of the recipient descriptor types pointed to by <tt><font
FACE="Courier">Recips</font></tt>. A value of 0 indicates that no recipients are included.
</td>
</tr>
<tr>
<td WIDTH="115"><tt><font FACE="Courier">FileCount</font></tt> </td>
<td WIDTH="84">Long</td>
<td WIDTH="391">A count of the file attachment descriptor types pointed to by <tt><font
FACE="Courier">Files</font></tt>. A value of 0 indicates that no file attachments are
included. </td>
</tr>
</table>
</center></div>
<p>Listing 6.1 shows how the <tt><font FACE="Courier">MAPIMessage</font></tt> structure is
built using Visual Basic 4.0. </p>
<div align="center"><center>
<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
<tr>
<td><b>Note</b></td>
</tr>
<tr>
<td><blockquote>
<p>The user-defined types and API calls are all contained in the <tt><font FACE="Courier">VBAMAP32.BAS</font></tt>
and <tt><font FACE="Courier">VBAMAPI16.BAS</font></tt> modules on the CD-ROM. You do not
have to type these structures and API calls into your projects. </p>
</blockquote>
</td>
</tr>
</table>
</center></div>
<blockquote>
</blockquote>
<hr>
<blockquote>
<b><p>Listing 6.1. The <tt><font FACE="Courier">MAPIMessage</font></tt> user-defined type.<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>'*************************************************** <br>
' MAPI Message holds information about a message <br>
'***************************************************<br>
<br>
Type MapiMessage<br>
Reserved As Long<br>
Subject As String<br>
NoteText As String<br>
MessageType As String<br>
DateReceived As String<br>
ConversationID As String<br>
Flags As Long<br>
RecipCount As Long<br>
FileCount As Long<br>
End Type</font></tt> </p>
</blockquote>
<hr>
<h4><tt><font FACE="Courier">MAPIRecip</font></tt></h4>
<p>The <tt><font FACE="Courier">MAPIRecip</font></tt> structure holds all the important
data related to a message recipient. Table 6.2 describes the structure, and Listing 6.2
shows how it looks in VBA code.<br>
</p>
<p align="center"><b>Table 6.2. The <tt><font FACE="Courier">MAPIRecip</font></tt>
structure.</b> </p>
<div align="center"><center>
<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
<tr>
<td><i>Field</i></td>
<td WIDTH="61"><i>Type</i></td>
<td WIDTH="411"><i>Description</i></td>
</tr>
<tr>
<td WIDTH="118"><tt><font FACE="Courier">Reserved</font></tt> </td>
<td WIDTH="61">Long</td>
<td WIDTH="411">Reserved for future use. This field must be 0. </td>
</tr>
<tr>
<td WIDTH="118"><tt><font FACE="Courier">RecipClass</font></tt> </td>
<td WIDTH="61">Long</td>
<td WIDTH="411">Classifies the recipient of the message. (Different classes can be used to
sort messages by the recipient class.) It can also contain information about the
originator of an inbound message. </td>
</tr>
<tr>
<td WIDTH="118"><tt><font FACE="Courier">Name</font></tt></td>
<td WIDTH="61">String</td>
<td WIDTH="411">The name of the recipient that is displayed by Mail. </td>
</tr>
<tr>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -