Search code examples
c#outlookoffice365exchangewebservices

Get Signature from Exchange


For some accounts of my company I can't get the email signature. I use the following code to retrieve signatures:

OWAConfig = UserConfiguration.Bind(_service, "OWA.UserOptions", WellKnownFolderName.Root, UserConfigurationProperties.Dictionary);

Normally it works fine but for some accounts, it throws :

The specified object was not found in the store., The configuration object was not found. Name = OWA.UserOptions.


Solution

  • That error will occur for accounts where they have never logged onto OWA before. The UserConfiguration object won't exist for those accounts and you won't be able to bind to it in code.

    You can check for the UserConfiguration object first and then create it, if it doesn't exist:

    SearchFilter sf = new SearchFilter.IsEqualTo(ItemSchema.ItemClass, "IPM.Configuration.OWA.UserOptions");
    ItemView iv = new ItemView(1);
    iv.Traversal = ItemTraversal.Associated;
    FindItemsResults<Item> fiResults = Root.FindItems(sf, iv);
    UserConfiguration OWAConfig  =null;
    if (fiResults.Items.Count == 0)
    {
       OWAConfig = new UserConfiguration(service);
       OWAConfig.Save("OWA.UserOptions", Root.ParentFolderId);                
    }
    

    Note: Creating a new UserConfiguration object may cause issues as it doesn't set the first time OWA logon settings, Regional settings etc. You will need to test the affected accounts for this and rectify them accordingly.