October 2000
Intermediate to advanced
384 pages
10h 22m
English
After a MAPI session has been established, email messages can be sent and received. Example B-2 shows a subroutine that sends an email.
Example B-2. Sending Email
Private Sub SendMessage( )
Dim OutlookFolder As Outlook.MAPIFolder
Dim OutlookMailItem As Outlook.MailItem
Dim OutlookRecipient As Outlook.Recipient
' Run Outlook and establish a MAPI session.
ConnectToOutlook
' Get a reference to the Outbox. (Messages must be created in
' some folder.)
Set OutlookFolder = _
gOutlookApplication.Session.GetDefaultFolder(olFolderOutbox)
' Create a new mail item.
Set OutlookMailItem = OutlookFolder.Items.Add(olMailItem)
OutlookMailItem.Subject = "This is the subject."
OutlookMailItem.Body = "This is the body text."
' Add a recipient.
Set OutlookRecipient = OutlookMailItem.Recipients.Add("dg")
OutlookRecipient.Type = olTo
' Send the message.
OutlookMailItem.Send
' Clean up.
Set OutlookRecipient = Nothing
Set OutlookMailItem = Nothing
Set OutlookFolder = Nothing
DisconnectFromOutlook
End Sub ' SendMessageThe SendMessage subroutine in Example B-2 performs the following steps:
Calls the ConnectToOutlook subroutine (already
shown in Example B-1) to create an Application
object and store a reference to it in the global variable
gOutlookApplication.
Obtains a reference to the user’s Outbox folder. This is done by calling the NameSpace object’s GetDefaultFolder method. (The NameSpace object is referenced through the Application object’s Session property.)
The GetDefaultFolder method ...