locked
Using CDOEX to access public folder emails RRS feed

  • Question

  • Hi all,

    I'm looking for some documentation on using the CDOXM.DLL in C# or VB.NET. I need to access a public folder on my exchange server and access it's emails and their attachments but I haven't got any experience using CDOXM.

    I've searched google high and low for some example code to no avail. Can anyone help me or point me in the right direction?

    Thanks in advance!!

    Thursday, October 7, 2010 7:04 PM

Answers

  • This is because you haven't included target URI if your copying a message you need the full path your copying it to eg

    Url = "file://./backofficestorage/server.com/Public Folders/Source Folder/test_email.EML";
       sEmailDest = "file://./backofficestorage/server.com/Public Folders/Dest Folder/test_email.EML";

    Because you only specified the Target folder you moved the message to the URI occupied by the folder and overwrote what was their (eg the folder) this is why it got deleted.

    Cheers
    Glen

    • Marked as answer by Wilky27 Monday, November 1, 2010 9:33 PM
    Monday, November 1, 2010 12:40 AM

All replies

  • Here's what I have so far, but it's complete guesswork:

    string username = "";
          string password = "";
    
          CDO.Folder iFolder = new CDO.Folder();
          iFolder.DataSource.Open("http://server/exchange/Public Folders/Referrals/IL4U", null, 
            ConnectModeEnum.adModeRead, RecordCreateOptionsEnum.adFailIfNotExists, 
            RecordOpenOptionsEnum.adOpenSource, username, password);
    
          //foreach (?? somehow loop through all unread emails in folder)
          {
            int aNum = iMessage.Attachments.Count;
    
            for(int i=1;i<=aNum;i++)
            {
              fName = iMessage.Attachments[i].FileName;
              CDO.IBodyPart iPrt = iMessage.Attachments[i];
              iPrt.SaveToFile(@"c:\temp\" + fName);
          }
    
    Thanks.
    Thursday, October 7, 2010 7:45 PM
  • What version of Exchange are you using ? if you have 2007 or 2010 then use EWS (unless your writing a event sink on 2007)

    There are several limitations you should understand before trying to use CDOEX the first is that because CDOEX uses exoledb to access the mailstore it will only work directly on the Exchange server where the mailbox is located. Second CDOEX doesn't support specifying alternate credentials so it will always use the security context of the calling thread/process.

    From what your trying to do you can't enumerate messages from a folder using dex you need to use Exoledb and do a select on the folder create a recordset eg see http://support.microsoft.com/kb/310206

    Also a few things to note there is that read status on message stored in a public folder is generally users specific and stored per user in a structure that isn't programmatically accessible.

    If your after documentation i would suggest downloading the Exchange 2003 SDK.

    Cheers
    Glen

     

    Thursday, October 7, 2010 11:48 PM
  • Thanks Glen!

    I'm using Exchange 2003 or else the EWS would have been perfect.

    I'm not too bothered about the read status really, as long as I can get at the attachments!

    I'll give this a whirl as soon as I can!!

    Friday, October 8, 2010 5:59 PM
  • Hi all,

    Im getting an error when trying to connect to the public folder on line:

    ADODB.Connection oCn = new ADODB.Connection();
    oCn.Provider = "exoledb.datasource";
    oCn.Open("file://./backofficestorage/EXCHANGE/Referrals/IL4U/", "", "", -1);
    
    

    the error is:

      Message "Exception from HRESULT: 0x80150804" string

    Can anyone help?

    Thanks.

    Monday, October 18, 2010 7:50 PM
  • Your URL is wrong to access the public store it should be something like

    file://./backofficestorage/yourSMTPdomain.example.com/public folders/
    or use the http URI eg 
    http://server.example.com/public/reports/

    see

    http://msdn.microsoft.com/en-us/library/aa123685%28v=EXCHG.65%29.aspx

    and

    http://msdn.microsoft.com/en-us/library/aa123688%28v=EXCHG.65%29.aspx

    Cheers
    Glen

    Tuesday, October 19, 2010 7:02 AM
  • Hi Glen,

    That is what i'm using. EXCHANGE is the name of the server.

    Monday, October 25, 2010 6:31 PM
  • This is what you posted

    oCn.Open("file://./backofficestorage/EXCHANGE/Referrals/IL4U/", "", "", -1);

    You are using the file uri http://msdn.microsoft.com/en-us/library/aa123685%28v=EXCHG.65%29.aspx

    using the servername in the file uri is not correct (Please read the link) if you want to use the file URI you need to use something like file://./backofficestorage/youdefaultsmtpdomain.com/Referrals/IL4U/

    domain-name

    The fully qualified name of the domain that the user account is a part of, for example, "subdomain.example.com". Note that this domain name does not include the name of the server itself.

    Cheers
    Glen

    Monday, October 25, 2010 8:27 PM
  • Sorry, didn't read it properly!!

    Thanks Glen.

    Wednesday, October 27, 2010 4:26 PM
  • Right, i've managed to connect to the public folder, iterate through all the emails I want, strip the attachment out and save it. Now I just need to move emails from one folder to another.

    This is what I have so far:

    sUrl = "file://./backofficestorage/server.com/Public Folders/Source Folder/test_email.EML";
       sEmailDest = "file://./backofficestorage/server.com/Public Folders/Dest Folder/";
    
       ADODB.Record oRec = new Record();
       oRec.Open(sUrl, oCn, ConnectModeEnum.adModeReadWrite, RecordCreateOptionsEnum.adFailIfNotExists,
        RecordOpenOptionsEnum.adOpenRecordUnspecified, sUser, sPass);
       oRec.MoveRecord(sUrl, sEmailDest, sUser, sPass, MoveRecordOptionsEnum.adMoveOverWrite, false); 
       //oRec.CopyRecord(sUrl, sEmailDest, sUser, sPass, CopyRecordOptionsEnum.adCopyNonRecursive, false);
       oRec.Close();
       oRec = null;
    

    This doesn't throw an error but it does delete the destination folder, and removes the email from the source folder, which is worrying. Can anyone spot where i'm going wrong.

    Thanks again!!

    Friday, October 29, 2010 7:39 AM
  • This is because you haven't included target URI if your copying a message you need the full path your copying it to eg

    Url = "file://./backofficestorage/server.com/Public Folders/Source Folder/test_email.EML";
       sEmailDest = "file://./backofficestorage/server.com/Public Folders/Dest Folder/test_email.EML";

    Because you only specified the Target folder you moved the message to the URI occupied by the folder and overwrote what was their (eg the folder) this is why it got deleted.

    Cheers
    Glen

    • Marked as answer by Wilky27 Monday, November 1, 2010 9:33 PM
    Monday, November 1, 2010 12:40 AM
  • Delightful!

    Thanks for all your help Glen!

    Monday, November 1, 2010 9:33 PM