Connecting Tech Pros Worldwide Help | Site Map

CDO: Accessing message in Exchange Public Folder

 
LinkBack Thread Tools Search this Thread
  #1  
Old January 2nd, 2009, 06:35 AM
Newbie
 
Join Date: Mar 2007
Location: Sydney, Australia
Age: 26
Posts: 18
Default CDO: Accessing message in Exchange Public Folder

Hello all

I am trying to modify a CDO script that moves email messages out of a user's inbox and into a drop folder. I want to update it to use a Public Folder instead.

The portion of the original script that matters is:

Expand|Select|Wrap|Line Numbers
  1. ' URL used for Outlook Web Access
  2. strOWAURL = "http://servername/exchange/"
  3.  
  4. ' Login
  5.  
  6. Set objUserSess = CreateObject("MAPI.Session")
  7. objUserSess.Logon  , , , , , , strServerName & vbLF & strAccountName
  8.  
  9. ' Move each message
  10.  
  11. Set objFolder = objUserSess.Inbox
  12. For each objMsg in objFolder.Messages
  13.     for each strMsgField in objMsg.fields
  14.         if instr(strMsgField,"/Inbox/") > 0 then
  15.             set objWebMsg = createobject("CDO.Message") 
  16.             objWebMsg.datasource.open strOWAURL& strMailBoxName  & strMsgField
  17.             set stm = objWebMsg.getstream() 
  18.             stm.type = 2
  19.             stm.Charset = "x-ansi"
  20.             rfcmsg = stm.readtext
  21.             rfcmsg = "x-sender: " & objWebMsg.fields("urn:schemas:httpmail:from") & vbcrlf & rfcmsg
  22.             rfcmsg = "x-receiver: " &strListEmail & vbcrlf & rfcmsg
  23.             stm.position = 0 
  24.             stm.writetext = rfcmsg
  25.             stm.savetofile strPickupFolder & objMsg.ID  & ".eml"
  26.         end if
  27.     next
  28.     objMsg.Delete
  29. next
  30.  
My modified script is:

Expand|Select|Wrap|Line Numbers
  1. ' URL used for Outlook Web Access
  2. strOWAURL = "http://localhost/public/testfolder/"
  3.  
  4. Set objSession = CreateObject("MAPI.Session")
  5. objSession.Logon  , , , , , , strServerName & vbLF & strAccountName
  6.  
  7. ' Change from a user inbox to the Public Folder infostore
  8.  
  9. Set objInfoStores = objSession.InfoStores
  10. Set objInfoStore = objInfoStores.Item("Public Folders")
  11. Set objRootFold = objInfoStore.RootFolder
  12.  
  13. Set objFolder = objRootFold.Folders(2).Folders("TestFolder")
  14.  
  15. For each objMsg in objFolder.Messages
  16.     for each strMsgField in objMsg.fields
  17.  
  18.             ' deleted line if instr(strMsgField,"/Inbox/") > 0 then
  19.             ' couldn't see the relevance in a Public Folder
  20.             ' with no subfolders
  21.  
  22.             set objWebMsg = createobject("CDO.Message") 
  23.  
  24.             ' this is the line that doesn't work below
  25.             ' the error is that it can't find the message
  26.  
  27.             objWebMsg.datasource.open strOWAURL & strMsgField
  28.  
So my question is, how can I open the message with the datasource.open method, given that we are now talking about a message object in a public folder, not a user's inbox?

I'm totally new to VB, so if I have made some outrageous and/or idiotic error, then I am not surprised (and I apologise in advance!).

Thanks for your help.
Reply
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.