none
Get mail items in shared folder RRS feed

  • Question

  • Hi, 

    i want to get mail items in a shared folder. I have tried different ways but i havent got all the way. Any suggestions or help please  :)

    Thanks in advance

    Outlook.Search search = null;
    Outlook.Results result = null;
    Outlook.MailItem item = null;
    var app = new Outlook.Application(); 
    var ns = app.GetNamespace("MAPI");
    search = app.AdvancedSearch("'\\\\Gemensamma mappar - bla@bla.se\\Alla gemensamma mappar\\Support\\Ankomna'", "urn:schemas:mailheader:subject LIKE '%1116958%'", true, "MySearch");
    result = search.Results;
    
    ??????
    

    Friday, December 16, 2016 6:09 AM

Answers

  • Found it :) This seems to work

    string sFilter = "@SQL=" + "\"" + "urn:schemas:httpmail:subject" + "\"" + " like '%1030852%'";

    • Marked as answer by Ollza Wednesday, December 28, 2016 9:40 AM
    Wednesday, December 28, 2016 9:40 AM

All replies

  • Hi Ollza,

    What is your Shared Folder? Is it a Folder others share you? I suggest you try to implement below code in C#.

    Sub GetSharedFolder()
      Dim NS As Outlook.NameSpace
      Dim objOwner As Outlook.Recipient   
      Set NS = Application.GetNamespace("MAPI")
      Set objOwner = NS.CreateRecipient("shared folder’s owner name")
        objOwner.Resolve       
     If objOwner.Resolved Then
       'MsgBox objOwner.Name
     Set newCalFolder = NS.GetSharedDefaultFolder(objOwner, olFolderInbox)
     End If

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 19, 2016 8:40 AM
  • That just gives me my inbox. The folder is shared to everybody in the company.

    Maybe this picture can explain it. I want to get items in a folder under the red line. As you see the green and red line is not located under my inbox.


    • Edited by Ollza Wednesday, December 21, 2016 10:33 AM
    Wednesday, December 21, 2016 10:33 AM
  • Hi Ollza,

    >> That just gives me my inbox

    What is value you enter for NS.CreateRecipient? I could not think out the reason that you get your own inbox with other’s alias in NS.CreateRecipient.

    I would suggest you share us your code and a new screen shot about your outlook. Note, please do not clean up all the email account, just clean up part of them, and then we could identity whether you set wrong value.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, December 22, 2016 8:23 AM
  • Oki, here is my code so far:

    Outlook.Recipient recip = null;
    var app = new Outlook.Application();
    var ns = app.GetNamespace("MAPI");
    recip = ns.CreateRecipient("Gemensamma mappar - bla@bla.se");
    recip.Resolve();
    if (recip.Resolved)
     {
    var folder = ns.GetSharedDefaultFolder(recip, Outlook.OlDefaultFolders.olFolderInbox);
    MessageBox.Show(recip.Name); //This is the "Inbox"
    }

    This is a better picture. I want to get items in the folder abow the red line

    Thursday, December 22, 2016 2:53 PM
  • Hi Ollza,

    I suggest you try something like below:

    Sub getSharedItems()
      Dim NS As Outlook.NameSpace
      Dim objOwner As Outlook.Recipient
      Dim f As Outlook.Folder
      Dim e As Outlook.MailItem
      Set NS = Application.GetNamespace("MAPI")
      Set objOwner = NS.CreateRecipient("Gemensamma mappar - bla@bla.se")
        objOwner.Resolve
      If objOwner.Resolved Then
       ‘ check the folder path 
        For Each e In NS.Folders(objOwner.Name).Folders("Alla gemensamma mappar").Folders("Support").Folders("Ankomna").Items
            Debug.Print e.Subject
        Next e
      End If
    End Sub

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Tony---- Thursday, December 29, 2016 6:27 AM
    Friday, December 23, 2016 5:40 AM
  • Thanks! I Found a way to get to the folder. but now i have another problem. i want to perform a search for specific items in that folder but it always gets null. There are around 6000 items in the folder and it takes to much time to loop the folder. 

    Any clu?

      protected static void GetOutlookItemsWithTicketNumberInSubject(string sTicketNo)
            {
                SupportMailItem oSupportMailitem = null;
                Outlook.Items items = null;
                Outlook.Application oOutlookApplication = new Outlook.Application();
                Outlook.NameSpace oOutlookNameSpace = oOutlookApplication.GetNamespace("MAPI");
    
                foreach (Outlook.MAPIFolder folders in oOutlookNameSpace.Folders)
                {
                    if (folders.Name.Contains("Gemensamma mappar")) //I need to have this beacuse this hase different names in different outlook versions.
                    {
                        //With this items is null
                        //items = folders.Folders["Alla gemensamma mappar"].Folders["Support"].Folders["Ankomna"].Items.Find("[Subject] = '1030979'"); 
    
                        //With this items.Count = 0 but it schould be 2
                        items = folders.Folders["Alla gemensamma mappar"].Folders["Support"].Folders["Ankomna"].Items.Restrict("[Subject] = '1030979'"); 
                    }
                }
                //This loop takes a little bit to much time
                foreach (Outlook.MailItem oMailItem in items)
                {
                    if (oMailItem.Subject != null)
                    {
                        if (oMailItem.Subject.Contains(sTicketNo))
                        {
                            oSupportMailitem = new SupportMailItem(oMailItem.EntryID);
                            oSupportMailitem.Subject = oMailItem.Subject;
                            oSupportMailitem.Sender = oMailItem.Sender.Name;
                        }
                    }
    
                }            
            }


    • Edited by Ollza Wednesday, December 28, 2016 8:09 AM
    Wednesday, December 28, 2016 8:09 AM
  • Found it :) This seems to work

    string sFilter = "@SQL=" + "\"" + "urn:schemas:httpmail:subject" + "\"" + " like '%1030852%'";

    • Marked as answer by Ollza Wednesday, December 28, 2016 9:40 AM
    Wednesday, December 28, 2016 9:40 AM