By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,888 Members | 1,552 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,888 IT Pros & Developers. It's quick & easy.

CDO: Accessing message in Exchange Public Folder

P: 20
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.
Jan 2 '09 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.