This documentation is archived and is not being maintained.

IMessages Interface

Exchange Server 2003

IMessages Interface

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

The IMessages interface defines methods and properties used to access a collection of Message objects retrieved by a call to GetMessages Method.

Because IMessages is only used for accessing messages on a file system, it is not useful in CDO for Microsoft® Exchange 2000 where messages are saved in the Exchange store.





Type Library

Microsoft CDO for Exchange 2000 Library

DLL Implemented In


Member Summary

The following table lists the properties of the IMessages interface.

Name Description
_NewEnum Returns an IEnumVARIANT interface on an object that can be used to enumerate the collection.
Count Returns the number of Message objects contained in the collection. This property is read-only.
FileName Returns the name of the file containing the message on the file system. This property is read-only.
Item Returns the specified Message object from the collection. This property is read-only.

The following table lists the methods of the IMessages interface.

Name Description
Delete Deletes the specified Message object in the collection and from the file system.
DeleteAll Deletes all Message objects in the collection along with all associated files on the file system.


The IDropDirectory.GetMessages method is used to return a collection of messages from a specified file system directory. The object reference returned by this method is of type IMessages. You can use this object to manage the collection of messages returned. You can get the total count of Message objects in the collection, retrieve one of the messages using the IMessages.Item method, and get the name of the file housing the message on the file system using the IMessages.Filename property.


This hypothetical example demonstrates how you could use the DropDirectory object (exposing the IDropDirectory interface) to enumerate the messages in the SMTP default drop directory and then copy each message addressed to a particular local account into an appropriate account mailbox directory. For example, you could have the local Administrator account's personal mail directory in the "c:\mailboxes\administrator" directory.

[Visual Basic]

Dim iDropDir as New CDO.DropDirectory
Dim iMsgs as CDO.IMessages
Dim iMsg as CDO.Message
Dim iStream as ADODB.Stream

Dim strTo as String
Dim ToRecipients as Variant
Dim strEmailName as String
Dim strAccountName as String
Dim strFileName as String
Dim strMailboxDir as String

Set iMsgs = iDropDir.GetMessages

For Each iMsg in iMsgs
  strFileName = iMsgs.FileName(iMsg)

  ' trim to get the short file name
  ' from the full path
  strFileName = Right(strFileName, Len(strFileName) - InStrRev(strFileName,"\") )

  ' Get the To recipients...and assume they are all local accounts
  strTo = iMsg.To
  ToRecipients = Split(strTo,",")
  Dim j, lpos, rpos, posdiff
  ' loop through recipients and get account names for each
  ' Each address will be in either the "Name" <name@tld> or
  '  simply <name@tld>
  ' We get the account name by getting the string
  ' between "<" and "@"
  For j = LBound(ToRecipients) to UBound(ToRecipients)
    strEmailName = ToRecipients(j)
    lpos = InStr(strEmailName,"<")
    rpos = InStr(strEmailName,"@")
    posdiff = rpos - lpos - 1
    strAccountName = Mid(strEmailName,lpos + 1, posdiff)

    ' For the purposes of this example,
    ' each account's mailbox directory resides in the
    ' directory c:\mailboxes. For user Joe, their account
    ' directory would be c:\mailboxes\joe
    strMailboxDir = "c:\mailboxes\" & strAccountName
    ' Get the message stream
    Set iStream = iMsg.GetStream

    ' write the stream to the user's mailbox directory
    ' the file name is the same as the one in the drop directory
    iStream.SaveToFile strMailboxDir & "\" & strFileName
    Set iStream = Nothing
  Next j
Next iMsg

' delete the picked up messages
' this deletes the files from the file system as well.

Set iMsgs = Nothing
Set iDropDir = Nothing


#import "d:\program files\common files\system\ado\msado15.dll" no_namespace raw_interfaces_only
#import <cdosys.dll> no_namespace raw_interfaces_only
#include <iostream.h>
#include <assert.h>
#include <wchar.h>

void main(int argc, char* argv[])

  IDropDirectory* pDropDir = NULL;
  IMessages*      pMsgs    = NULL;
  IUnknown*       pUnk     = NULL;
  IEnumVARIANT*   pEnum    = NULL;


  long count = 0;
  cout << count << endl;


   ULONG cFetched = 0;
   VARIANT var;
   while (1) {
      cFetched = 0;
      cout << "fetched: " << cFetched << endl;
      if(cFetched == 0)
      assert(var.vt == VT_DISPATCH);
      IMessage* pMsg = NULL;

       VARIANT varIntf;
       V_VT(&varIntf) = VT_DISPATCH;
       varIntf.pdispVal = pMsg;
       BSTR szFilename;

       cout << _bstr_t(szFilename) << endl;
       wchar_t* pwchar;
       pwchar = wcsrchr(szFilename,'\\');
       _bstr_t mailfilename(pwchar+1);
       BSTR to;
       wchar_t* pWChar = to;

       wchar_t szbuffer[100];
       wchar_t lt = '<';
       wchar_t amp = '@';
       wchar_t* pFirst;
       unsigned int curPos = 0;
       _bstr_t mailboxesroot = "c:\\mailboxes\\";

       for(unsigned int k = 0;k<wcslen(pWChar);k++){
          if(pWChar[k] == lt) {
          pFirst = &pWChar[k];
          curPos = k;
       if(pWChar[k] == amp) {
          cout << "amp" << endl;
          buffer[k-curPos-1] = (wchar_t)'\0';
         _bstr_t filen = mailboxesroot + _bstr_t(buffer) + "\\" + _bstr_t(mailfilename);
         _Stream* pStrm = NULL;