Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Table 21.1 MAPIMessages control email methods.
Function Method
Get email from Inbox Fetch
Send email with Compose box Send
Send email Send
Save a message Save
Copy a message for reply Copy
Compose email Compose
Reply to a message Reply
Reply to all messages ReplyAll
Forward a message Forward
Delete a message Delete
Show address book Show
Show message details Show
Resolve recipient name ResolveName
Delete recipient Delete
Delete attachment Delete

Table 21.2 MAPIMessages control properties.
Property Description
Action Obsolete. Performs actions now performed by methods.
AddressCaption Sets caption of the address book.
AddressEditFieldCount Sets which address book edit controls to display.
AddressLabel Sets appearance of “To” edit control in address book.
AddressModifiable Sets whether address book can be modified by user.
AttachmentCount Gets total number of attachments for current message.
AttachmentIndex Sets currently indexed attachment.
AttachmentName Sets name of the currently indexed attachment.
AttachmentPathName Sets full path name of the currently indexed attachment.
AttachmentPosition Sets position of indexed attachment in the message body.
AttachmentType Sets type of currently indexed attachment.
FetchSorted Sets message order when creating message set.
MsgConversationID Sets the conversation thread identification value.
MsgCount Gets the total number of messages in message set.
MsgDateReceived Gets date on which current indexed message was received.
MsgID Gets string identifier of current message.
MsgIndex Sets index number of current message.
MsgNoteText Text of current message.
MsgOrigAddress Gets email address of originator of current message.
MsgOrigDisplayName Gets originator’s name for current message.
MsgRead True or False depending on whether message has been read.
MsgReceiptRequested Indicates if return receipt is requested for message.
MsgSent Indicates if message has been sent to mail server.
MsgSubject Message’s subject.
MsgType Sets type of current message.

Sending Email From Visual Basic

Now that you’ve added the MAPISession and MAPIMessages control to your program (see the previous topic), how do you use them to send email? Let’s see an example. Create a new standard EXE project, and add the MAPISession and MAPIMessages controls MAPISession1 and MAPIMessages1. Next add two command buttons, Command1 and Command2, with the captions “Send email” and “Read email”. We’ll enable Command1, the Send Email button, in this topic, and Command2, the Read Email button, in the next topic. In addition, we’ll need some place to display the email we’ve read, so add a text box, Text1, to the form, setting its MultiLine property to True and its ScrollBars property to Both (3).

When users click Command1, they want to send email, and we let them do so by using the MAPIMessages control’s Compose and Send methods. Our first task, however, is to start a new MAPI session, and we do that with the MAPISession control’s SignOn method, after indicating that we don’t want to download email by setting its DownLoadMail property to False:

Private Sub Command1_Click()

    MAPISession1.DownLoadMail = False
    MAPISession1.SignOn

...

After signing on to the Microsoft Exchange email system, we set the MAPIMessages control’s SessionID to the MAPISession control’s SessionID property to initialize MAPIMessages1:

Private Sub Command1_Click()

    MAPISession1.DownLoadMail = False
    MAPISession1.SignOn

    MAPIMessages1.SessionID = MAPISession1.SessionID
...

To compose a new email message, we have to set the MAPIMessages1 control’s MsgIndex property to -1 and call its Compose method:

Private Sub Command1_Click()

    MAPISession1.DownLoadMail = False
    MAPISession1.SignOn
    MAPIMessages1.SessionID = MAPISession1.SessionID
    MAPIMessages1.MsgIndex = -1
    MAPIMessages1.Compose
...

This code displays the Compose dialog box, as shown in Figure 21.12. Users can enter the email text and address they want to use in that dialog box and click the Send button (the Send button displays an envelope in Figure 21.12) to send their email.


Figure 21.12  Composing an email message.

When the user is done composing the email, we send it with the MAPIMessages1 control’s Send method and sign off the MAPI session using the MAPISession1 control’s SignOff method:

Private Sub Command1_Click()

    MAPISession1.DownLoadMail = False
    MAPISession1.SignOn

    MAPIMessages1.SessionID = MAPISession1.SessionID
    MAPIMessages1.MsgIndex = -1
    MAPIMessages1.Compose
    MAPIMessages1.Send True

    MAPISession1.SignOff
End Sub

That’s it—we’ve sent our email. What actually happens is that the program sends the new email message to the user’s Outbox (which is also opened when you open the Inbox), and the Outbox is usually set to send email automatically. In fact, that’s the way the Microsoft Exchange usually works: by logging into the mail server you’ve specified at regular intervals. When it logs in, it sends the mail waiting in the Outbox and reads any waiting email, placing it in the Inbox. (In fact, now that we’ve sent email, we’ll see how to read that email in the next topic.)

The code for this example, email.frm version 1 (version 2, which is located on this book’s accompanying CD-ROM, will let the user read email as well), appears in Listing 21.3.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.