none
How to create an OWA email signature by using EWS RRS feed

  • Question

  • I want to update the signature for my OWA email on Exchange server 2010 by using EWS.

    I can do that by using webdav but only on the previous version of Exchange server because webdav is no longer available on exchange 2010. 

    Does anyone help me asap?


    Thanks

    Sunday, February 20, 2011 2:58 PM

Answers

  • You can use a userconfiguration operation http://msdn.microsoft.com/en-us/library/dd899549(v=exchg.140).aspx on 2010 eg in the EWS Managed API something like this

    static void SetSigniture(ExchangeService service) {
          service.TraceEnabled = true;
          Folder Root = Folder.Bind(service, WellKnownFolderName.Root);
          UserConfiguration OWAConfig = UserConfiguration.Bind(service, "OWA.UserOptions", Root.ParentFolderId, UserConfigurationProperties.All);
          String hsHtmlSigniture = "www.blah.com\">Glen Scales";
          String stTextSig = "Text sig";
    
          if(OWAConfig.Dictionary.ContainsKey("signaturehtml")){
            OWAConfig.Dictionary["signaturehtml"] = hsHtmlSigniture;
          }
          else
          {
            OWAConfig.Dictionary.Add("signaturehtml", hsHtmlSigniture);
          }
          if (OWAConfig.Dictionary.ContainsKey("signaturetext"))
          {
            OWAConfig.Dictionary["signaturetext"] = stTextSig;
          }
          else
          {
            OWAConfig.Dictionary.Add("signaturetext", stTextSig);
          }
          OWAConfig.Update();
        }
    
    Cheers
    Glen
    Monday, February 21, 2011 2:08 AM

All replies

  • You can use a userconfiguration operation http://msdn.microsoft.com/en-us/library/dd899549(v=exchg.140).aspx on 2010 eg in the EWS Managed API something like this

    static void SetSigniture(ExchangeService service) {
          service.TraceEnabled = true;
          Folder Root = Folder.Bind(service, WellKnownFolderName.Root);
          UserConfiguration OWAConfig = UserConfiguration.Bind(service, "OWA.UserOptions", Root.ParentFolderId, UserConfigurationProperties.All);
          String hsHtmlSigniture = "www.blah.com\">Glen Scales";
          String stTextSig = "Text sig";
    
          if(OWAConfig.Dictionary.ContainsKey("signaturehtml")){
            OWAConfig.Dictionary["signaturehtml"] = hsHtmlSigniture;
          }
          else
          {
            OWAConfig.Dictionary.Add("signaturehtml", hsHtmlSigniture);
          }
          if (OWAConfig.Dictionary.ContainsKey("signaturetext"))
          {
            OWAConfig.Dictionary["signaturetext"] = stTextSig;
          }
          else
          {
            OWAConfig.Dictionary.Add("signaturetext", stTextSig);
          }
          OWAConfig.Update();
        }
    
    Cheers
    Glen
    Monday, February 21, 2011 2:08 AM
  • Thank a lot, Glen. It looks a great code but anyway I encountered a problem at the line 

    	Folder Root = Folder.Bind(service, WellKnownFolderName.Root);

    it throws an exception: Request failed. The remote server returned an error: (404) Not Found.

    Below are the code snippet:

        ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);

                service.Credentials = new NetworkCredential("mbc", "aod@123", "meocon");

                service.Url = new Uri("http://192.168.1.57/EWS/exchange.asmx");

                SetSigniture(service);

     

    Could you please advise?

     

    Tuesday, February 22, 2011 8:44 AM
  • Have you used EWS before on this server ?? is 192.168.1.57 a CAS server that type of error indicate you can't access the EWS virtual directory which http://192.168.1.57/EWS/exchange.asmx is reverencing. Exchange won't allow communication on http by default either so the first thing i would try is use https instead and also include a line in first just to ignore any SSL errors eg

    ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
    service.Url = new Uri("https://192.0.0.0/EWS/Exchange.asmx");

    Cheers
    Glen

    Wednesday, February 23, 2011 2:40 AM
  • Great! I get it working now :)

    Thank you a lot

    Wednesday, February 23, 2011 4:03 AM
  • I am feeling little difficulty to understanding the code.
    Could you please describe this code & field values for better understandings.

    I would be very thankful of you.

    • Proposed as answer by pavani229 Tuesday, December 8, 2015 5:38 AM
    Monday, January 7, 2013 10:12 AM
  • Its pretty basic which part don't you understand I would suggest reading this first http://msdn.microsoft.com/en-us/library/dd899549(v=exchg.140).aspx and also this protocol document may help http://msdn.microsoft.com/en-us/library/ee218303(v=exchg.80).aspx.

    If you have a specific question then you should create your question around that including any errors etc you get.

    Cheers
    Glen

    Tuesday, January 8, 2013 5:36 AM
  • Hi Glen

    I want to update the default signature in outlook 2010 desktop client as well as outlook 2010 web client by EWS[Exchange Web Services].

    How do we do this???

    Thank You in Advance... :)

    Wednesday, January 23, 2013 6:27 AM
  • EWS wont help with this because the Outlook client signiture is held locally on the PC in drive:\Users\user\AppData\Roaming\Microsoft\Signatures

    So you need to use local code on that PC to modify\set a user signiture eg search the outlook forum http://social.msdn.microsoft.com/Search/en-US/office?query=signiture&rq=meta:Search.MSForums.ForumID(fd2e7273-6db9-4bba-9200-a91e143827aa)+site:microsoft.com&rn=Outlook+for+Developers+Forum

    Cheers
    Glen

    Thursday, January 24, 2013 6:08 AM
  • Hi Glen

    here is my java code

    Folder root = Folder.bind(service, WellKnownFolderName.Root);
                UserConfiguration user = UserConfiguration.bind(service,
                        "OWA.UserOptions", root.getParentFolderId(),
                        UserConfigurationProperties.All);
                System.out.println(user.getDictionary().getElements("signaturetext"));
                
                if (user.getDictionary().containsKey("signaturetext"))
                    user.getDictionary().setElements("signaturetext", "karri");
                else
                    user.getDictionary().addElement("signaturetext", "karri");
                
                System.out.println(user.getDictionary().getElements("signaturetext"));
                user.update();


    I am able to print the old and new signatures on the console . But when the update step is executed I m getting the following exception

    0    [main] INFO  org.apache.commons.httpclient.auth.AuthChallengeProcessor  - NTLM authentication scheme selected
    nitin
    karri
    java.lang.ClassCastException: java.lang.String cannot be cast to [Ljava.lang.String;
        at microsoft.exchange.webservices.data.UserConfigurationDictionary.writeObjectValueToXml(Unknown Source)
        at microsoft.exchange.webservices.data.UserConfigurationDictionary.writeObjectToXml(Unknown Source)
        at microsoft.exchange.webservices.data.UserConfigurationDictionary.writeElementsToXml(Unknown Source)
        at microsoft.exchange.webservices.data.ComplexProperty.writeToXml(Unknown Source)
        at microsoft.exchange.webservices.data.ComplexProperty.writeToXml(Unknown Source)
        at microsoft.exchange.webservices.data.UserConfiguration.writeToXml(Unknown Source)
        at microsoft.exchange.webservices.data.UpdateUserConfigurationRequest.writeElementsToXml(Unknown Source)
        at microsoft.exchange.webservices.data.ServiceRequestBase.writeBodyToXml(Unknown Source)
        at microsoft.exchange.webservices.data.ServiceRequestBase.writeToXml(Unknown Source)
        at microsoft.exchange.webservices.data.ServiceRequestBase.buildEwsHttpWebRequest(Unknown Source)
        at microsoft.exchange.webservices.data.ServiceRequestBase.validateAndEmitRequest(Unknown Source)
        at microsoft.exchange.webservices.data.SimpleServiceRequestBase.internalExecute(Unknown Source)
        at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(Unknown Source)
        at microsoft.exchange.webservices.data.ExchangeService.updateUserConfiguration(Unknown Source)
        at microsoft.exchange.webservices.data.UserConfiguration.update(Unknown Source)
        at client.Exchange.main(Exchange.java:46)

    Note: line 46 is   user.update();

    I  tried passing a string array in the place of string to get rid of that string array cast exception. But still I got the same error.

    when  I tried to set the autoaddsignature to true(boolean)

    user.getDictionary().setElements("autoaddsignature", true);

    I got the following exception

    0    [main] INFO  org.apache.commons.httpclient.auth.AuthChallengeProcessor  - NTLM authentication scheme selected
    microsoft.exchange.webservices.data.ServiceLocalException: Objects of type %s can't be added to the dictionary. The following types are supported: string array, byte array, boolean, byte, DateTime, integer, long, string, unsigned integer, and unsigned long.,class java.lang.Boolean
        at microsoft.exchange.webservices.data.UserConfigurationDictionary.validateObjectType(Unknown Source)
        at microsoft.exchange.webservices.data.UserConfigurationDictionary.validateObject(Unknown Source)
        at microsoft.exchange.webservices.data.UserConfigurationDictionary.validateEntry(Unknown Source)
        at microsoft.exchange.webservices.data.UserConfigurationDictionary.setElements(Unknown Source)
        at client.Exchange.main(Exchange.java:40)

    Kindly help me out

    Tuesday, January 29, 2013 7:04 PM
  • Sorry I'm not a Java person but did you look at the types being used when you get the Configuration you should just be able to match the types being used. The error point to validation of the types failing

    Cheers
    Glen

    Wednesday, January 30, 2013 6:08 AM
  • You can use a userconfiguration operation http://msdn.microsoft.com/en-us/library/dd899549(v=exchg.140).aspx on 2010 eg in the EWS Managed API something like this

    static void SetSigniture(ExchangeService service) {
          service.TraceEnabled = true;
          Folder Root = Folder.Bind(service, WellKnownFolderName.Root);
          UserConfiguration OWAConfig = UserConfiguration.Bind(service, "OWA.UserOptions", Root.ParentFolderId, UserConfigurationProperties.All);
          String hsHtmlSigniture = "www.blah.com\">Glen Scales";
          String stTextSig = "Text sig";
    
          if(OWAConfig.Dictionary.ContainsKey("signaturehtml")){
            OWAConfig.Dictionary["signaturehtml"] = hsHtmlSigniture;
          }
          else
          {
            OWAConfig.Dictionary.Add("signaturehtml", hsHtmlSigniture);
          }
          if (OWAConfig.Dictionary.ContainsKey("signaturetext"))
          {
            OWAConfig.Dictionary["signaturetext"] = stTextSig;
          }
          else
          {
            OWAConfig.Dictionary.Add("signaturetext", stTextSig);
          }
          OWAConfig.Update();
        }
    
    Cheers
    Glen

    Thank you Glen for your code but is creating an issue

    I am using your code to set up the OWA email Signature using EWS but it is creating an error at 

    UserConfiguration OWAConfig = UserConfiguration.Bind(service, "OWA.UserOptions", Root.ParentFolderId, UserConfigurationProperties.All);

    The error it is reporting is:

    The Specified Object was not found in the store. Microsoft.Exchange.WebServices.Data.ServiceResponseException was caught   HResult=-2146233088   Message=The specified object was not found in the store.   Source=Microsoft.Exchange.WebServices   StackTrace:        at Microsoft.Exchange.WebServices.Data.ServiceResponse.InternalThrowIfNecessary()        at Microsoft.Exchange.WebServices.Data.ServiceResponse.ThrowIfNecessary()        at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()        at Microsoft.Exchange.WebServices.Data.ExchangeService.GetUserConfiguration(String name, FolderId parentFolderId, UserConfigurationProperties properties)        at Microsoft.Exchange.WebServices.Data.UserConfiguration.Bind(ExchangeService service, String name, FolderId parentFolderId, UserConfigurationProperties properties)

    Microsoft.Exchange.WebServices.Data.ServiceResponseException was caught
      HResult=-2146233088
      Message=The specified object was not found in the store.
      Source=Microsoft.Exchange.WebServices
      StackTrace:
           at Microsoft.Exchange.WebServices.Data.ServiceResponse.InternalThrowIfNecessary()
           at Microsoft.Exchange.WebServices.Data.ServiceResponse.ThrowIfNecessary()
           at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
           at Microsoft.Exchange.WebServices.Data.ExchangeService.GetUserConfiguration(String name, FolderId parentFolderId, UserConfigurationProperties properties)
           at Microsoft.Exchange.WebServices.Data.UserConfiguration.Bind(ExchangeService service, String name, FolderId parentFolderId, UserConfigurationProperties properties)

    Please Help me to resolve this error.

    Thanx in advance.

    Wednesday, November 6, 2013 11:44 AM
  • If the user hasn't ever logged onto OWA before then the UserConfiguration object won't exist and you won't be able to bind to it. You can test this beforehand and create a new object if necessary using something like

                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);                
                }

      However the problem with creating a new object is it doesn't set the Regional settings and other first time OWA logon setting . So you may find when the user does eventually logon to OWA the missing setting may cause problems. You'll need to test that yourself.

    Cheers
    Glen

    Thursday, November 7, 2013 2:00 AM