Export (0) Print
Expand All

MailItem Object (Outlook)

Published: July 16, 2012

Represents a mail message.

Use the CreateItem method to create a MailItem object that represents a new mail message.

Use the Folder.Items property to obtain an Items collection representing the mail items in a folder, and the Items.Item (index) method, where index is the index number of a mail message or a value used to match the default property of a message, to return a single MailItem object from the specified folder.

The following Visual Basic for Applications (VBA) example creates and displays a new mail message.

Sub CreateMail() 
 
 Dim myItem As Object 
 
 
 
 Set myItem = Application.CreateItem(olMailItem) 
 
 myItem.Subject = "Mail to myself" 
 
 myItem.Display 
 
End Sub

The following VBA example sets the current folder as the Inbox and displays the second mail message in the folder. In general, the order of mail messages in a folder is not guaranteed to be in a particular order.

Sub DisplayMail() 
 
 Dim myItem As Object 
 
 Dim myFolder As Folder 
 
 
 
 Set myNamespace = Application.GetNamespace("MAPI") 
 
 Set myFolder = myNamespace.GetDefaultFolder(olFolderInbox) 
 
 myFolder.Display 
 
 Set myItem = myFolder.Items(2) 
 
 myItem.Display 
 
End Sub

Concepts

Other resources

How to: Send an E-mail Given the SMTP Address of an Account

Community Additions

ADD
Show:
© 2014 Microsoft