RE: Extracting information from Exchange

  • From: "Mulnick, Al" <Al.Mulnick@xxxxxxxxxx>
  • To: "[ExchangeList]" <exchangelist@xxxxxxxxxxxxx>
  • Date: Tue, 15 Mar 2005 14:19:01 -0500

It's supposed to return the folders, however the comments you used // are
not valid in VB.  You need to use the apostrophe ' as the comment.

You also don't need the C++ code.  

In order for this to work, you would have to provide a value for username
when calling this code.  That value is placed into the mailboxFolderURL
string which would be the path to your mailbox.

There also seems to be some wrapping in the code, so hopefully you caught
that and didn't let it wrap in your trial.

Al



-----Original Message-----
From: Sonya [mailto:sonya.mcneal@xxxxxxxx] 
Sent: Tuesday, March 15, 2005 1:54 PM
To: [ExchangeList]
Subject: [exchangelist] RE: Extracting information from Exchange

http://www.MSExchange.org/

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;
}


------------------------------------------------------
List Archives: http://www.webelists.com/cgi/lyris.pl?enter=exchangelist
Exchange Newsletters: http://www.msexchange.org/pages/newsletter.asp
Exchange FAQ: http://www.msexchange.org/pages/larticle.asp?type=FAQ
------------------------------------------------------
Other Internet Software Marketing Sites:
World of Windows Networking: http://www.windowsnetworking.com Leading
Network Software Directory: http://www.serverfiles.com
No.1 ISA Server Resource Site: http://www.isaserver.org Windows Security
Resource Site: http://www.windowsecurity.com/ Network Security Library:
http://www.secinf.net/ Windows 2000/NT Fax Solutions:
http://www.ntfaxfaq.com
------------------------------------------------------
You are currently subscribed to this MSEXchange.org Discussion List as:
al.mulnick@xxxxxxxxxx To unsubscribe visit
http://www.webelists.com/cgi/lyris.pl?enter=exchangelist
Report abuse to listadmin@xxxxxxxxxxxxxx


Other related posts: