RE: Extracting information from Exchange

  • From: "Sonya" <sonya.mcneal@xxxxxxxx>
  • To: exchangelist@xxxxxxxxxxxxx
  • Date: Tue, 15 Mar 2005 11:53:31 -0700

In trying to understand this code and the small documentation given via
MSDN, is this used to retrieve information from a users' folder in their
mailbox? Meaning, will I be able to query say, my mailbox and extract or
copy my contact list to export to a file or table?

<Job id="printMailboxURLs">

<reference object="ADODB.Record"/>
<reference object="CDO.Message"/>

<script language="VBScript">

userName   = WScript.Arguments.Item(0)

set info   = createobject("adsysteminfo")
set infoNT = CreateObject("WinNTSystemInfo")

urls = getStdWellKnownMailboxURLs("http://"; & lcase(infoNT.ComputerName) &
"." & _
                                 Info.domaindnsname & "/exchange/" &
userName, _
                                 "ExOLEDB.DataSource")

wscript.echo "Well-known mailbox file: URLs for local mailbox: " &
userName
wscript.echo "========================================"

For i = LBound(urls) to UBound(urls) step 2
 wscript.stdout.write urls(i)
 if Len(urls(i)) > 7 then
  wscript.stdout.write vbTab
 else
  wscript.stdout.write vbTab & vbTab
 end if
 wscript.stdout.write urls(i+1) & vbCrLf
next


Function getStdWellKnownMailboxURLs( mailboxFolderURL, provider )

 If Not TypeName(mailboxFolderURL) = "String" Then
  Err.Raise  &H80070057 ' E_INVALIDARG
 End If


 Dim Rec
 Set Rec = CreateObject("ADODB.Record")
 Dim Conn
 Set Conn = CreateObject("ADODB.Connection")
 Conn.Provider =  provider
 Conn.Open mailboxFolderURL

 Rec.Open mailboxFolderURL, Conn
 Set Flds = Rec.Fields

 ' The constants used here are defined in the CDOEx.dll type library.
 ' They are imported using the <reference> element above.

 getStdWellKnownMailboxURLs = Array( _
             // "Calendar" , Flds(cdoCalendarFolderURL), _
              "Contacts" , Flds(cdoContactFolderURL), _
             // "DeletedIt", Flds(cdoDeletedItems), _
             // "Inbox"    , Flds(cdoInbox), _
             // "Journal"  , Flds(cdoJournal), _
             // "MsgRoot"  , Flds(cdoMsgFolderRoot), _
             // "Notes"    , Flds(cdoNotes), _
             // "Outbox"   , Flds(cdoOutbox), _
             // "SendMsg"  , Flds(cdoSendMsg), _
             // "SendItems", Flds(cdoSentItems), _
             // "Tasks"    , Flds(cdoTasks) )

' Clean up.
Conn.Close
Rec.Close

Set Conn = Nothing
Set Rec = Nothing


End Function

</script>

</Job>


C++
#import <msado15.dll> no_namespace
#import <c:\program files\common files\microsoft shared\cdo\cdoex.dll> 
no_namespace
#include <iostream.h>

// Note: It is recommended that all input parameters be validated when
they are
// first obtained from the user or user interface.
void printMailboxFolders(bstr_t mailtoUrl) {

   IMailboxPtr iMbx;
   try {
      iMbx = getIMailbox(mailtoUrl);
   }
   catch(_com_error e) {
      throw e;
   }

   cout << "BaseFolder: " << iMbx->BaseFolder << endl;
   cout << "Inbox: "      << iMbx->Inbox << endl;
   cout << "Calendar: "   << iMbx->Calendar << endl;
   cout << "Drafts: "     << iMbx->Drafts << endl;

   //...

   IDataSourcePtr iDsrc;
   iDsrc = iMbx;
   cout << iDsrc->SourceURL << endl;
   _RecordPtr Rec(__uuidof(Record));
   _ConnectionPtr Conn(__uuidof(Connection));
   Conn->Provider = "ExOLEDB.DataSource";
   bstr_t sSendMsgUrl;
   try {
      Conn->Open(iMbx->BaseFolder, bstr_t(),bstr_t(), -1);
      Rec->Open(iMbx->BaseFolder, variant_t((IDispatch*)Conn, true),
adModeRead, adFailIfNotExists, adOpenRecordUnspecified, bstr_t(),
bstr_t());
      sSendMsgUrl =
bstr_t(Rec->Fields->Item["urn:schemas:httpmail:sendmsg"]->Value);
   }
   catch(_com_error e) {
      cout << "Error binding to user's base mailbox folder. " << endl;
      throw e;
   }
   cout << "Mail Submission URI: " << sSendMsgUrl << endl;

   // Close the connection and record.
   Conn->Close();
   Rec->Close();
   Rec = NULL;
   Conn = NULL;

}

// Note: It is recommended that all input parameters be validated when
they are
// first obtained from the user or user interface.
IMailboxPtr getIMailbox( bstr_t mailtoUrl) {

   IPersonPtr Per(__uuidof(Person));
   IDataSourcePtr Dsrc;
   Dsrc = Per;
   try {
      Dsrc->Open(mailtoUrl, NULL, adModeRead, adFailIfNotExists,
adOpenRecordUnspecified, bstr_t(),bstr_t());
   }
   catch(_com_error e) {
      throw e;
   }

   return Per;
}



Other related posts: