GetDefaultFolder Method (CDONTS Session Object)

The GetDefaultFolder method returns a Folder object from a message store.

Syntax

Set objFolder = objSession.GetDefaultFolder(folderType) 
 
objFolder
On successful return, contains the store's default Folder object of the specified type. When the folder does not exist, GetDefaultFolder returns Nothing.
objSession
Required. The Session object.
folderType
Required. Long. The folder type. This parameter can have exactly one of the following values:

folderType setting
Decimal
value

Meaning
CdoDefaultFolderInbox 1 The CDO for NTS Library's Inbox.
CdoDefaultFolderOutbox 2 The CDO for NTS Library's Outbox.

Remarks

The GetDefaultFolder method allows you to obtain the message store's default Inbox or Outbox folder. No other folders are accessible through this method.

Example

This code fragment uses the GetDefaultFolder method to obtain the Inbox folder from a message store:

Dim objSession As Session 
Dim objInbox As Folder ' default Inbox or Outbox 
Dim collMessages As Messages ' messages in folder 
 
Set objSession = CreateObject ("CDONTS.Session") 
objSession.LogonSMTP("My Name", "myaddress@mycompany.com") 
Set objInbox = objSession.GetDefaultFolder(CdoDefaultFolderInbox) 
If objInbox Is Nothing Then 
    Set collMessages = Nothing 
    MsgBox "Unable to retrieve default folder" 
    Exit Function 
Else 
    Set collMessages = objInbox.Messages 
    MsgBox "Folder set to " & objInbox.Name 
End If