Developing Outlook 2013 Add-in, issues trying to set EmailSignature options. RRS feed

  • Question

  • I am in the process of re-writing an Outlook Add-in that works fine in Outlook 2007.

    When testing the code in VS2013 with Outlook 2013 I am getting an System.InvalidCast Exception when trying to set the EmailOptions.EmailSignature.NewMessageSIgnature or .ReplyMessageSignature properties.

    The code that is failing is below.  I have tried to different ways to access the Word EmailOptions.  I have tried launching a new instance of Word and accessing the EmailSignature properties (which worked in Office 2007) as well as accessing the Word Object Model through Outlook which is the method I am using below.  The below method does not launch an instance of Winword.exe  both fail with the same error.  Any suggestions would be appreciated.

    Thanks in Advance.  


    Outlook.MailItem NewMail = (Outlook.MailItem)ThisAddIn._OApplication.CreateItem(Outlook.OlItemType.olMailItem); Outlook.Inspector NewInsp = NewMail.GetInspector; MSWord.Document appWordDoc = NewInsp.WordEditor; MSWord.Application appWord = appWordDoc.Application;

    <CODE FAILS on next Line after a lengthy pause receive the Error: System.InvalidCastException> appWord.EmailOptions.EmailSignature.NewMessageSignature = "EMailSig1"; appWord.EmailOptions.EmailSignature.ReplyMessageSignature = "EmailReplySig1";

    Thursday, September 17, 2015 9:33 PM


All replies

  • Hello Paul,

    I'd suggest breaking the chain of property and method calls and declaring them on separate line of code. So, you will be able to find what property or method exactly fires the exception.

    Outlook stores its signatures in the Signatures folder. The default folder where Outlook email signature files are located is:

    Windows XP: C:\Documents and Settings\%username%\Application Data\Microsoft\Signatures

    Windows 8 / 7 / Vista: C:\Users\%username%\AppData\Roaming\Microsoft\Signatures

    So, you can read the file content in folders instead.

    Friday, September 18, 2015 5:13 AM
  • Thank you for your response.  

    I am actually trying to set the signature.

    When troubleshooting and step through the code in Visual Studio (2015), I am unable to access the EmailSignature and any of it's sub properties (NewMessageSignature).

    When looking at all the documentation on Microsofts sight this is the way to do it.  The NewMessageSignature property is just a string.  So it is really confusing why it is not working.

    I am able to do this with no problem in Outlook 2007 and 2010.

    Friday, September 18, 2015 3:19 PM
  • You can't use the EmailSignature property in Outlook. Instead, you need to detect the sender and find the corresponding signature in the folder I mentioned. 
    Sunday, September 20, 2015 8:15 AM
  • Given what I am trying to do, that will not work for me.  

    I need to be able to configure the Signature Options.  I created a small Word Add-In and was able to access the EmailSignature Properties with no issues.

    Do you know if this is a trust issue?  Is there a way to allow Outlook to access this property?

    My Code is signed and is a trusted publisher.

    Monday, September 21, 2015 7:26 PM
  • EmailSignature properties make sense only in Word, not Outlook add-ins.
    Monday, September 21, 2015 9:40 PM