0

I'm writing an Outlook 2010 add-in with VSTO, one part of which will automatically add the correct email signature to a new AppointmentItem. The issue I've come across is how to determine which signature is the correct one. For example, I have 2 email signatures set up in Outlook, which have rules on use based on which address my email is coming from. How can I access these rules?

My issue is not with finding the signature files, but in applying the correct rules based on the user's settings. Any ideas?

Community
  • 1
  • 1
Kevin Pope
  • 2,964
  • 5
  • 32
  • 47

2 Answers2

0

You can access the rules by using the code below. You can loop through them and get the rule type and actions

app is the current instance of the Outlook.Application

Outlook.Rules rules= app.Session.DefaultStore.GetRules();
foreach (Outlook.Rule r in rules)
{

}
Sorceri
  • 7,870
  • 1
  • 29
  • 38
  • Not really what I'm looking for - this shows all the Folder's rules (like move an email from X to a certain folder), but doesn't cover the signature rules (when I have the signature dialog up, these rules are under the "Default Signature" heading) – Kevin Pope Sep 27 '12 at 23:27
  • I do not beleive there is a way though the com object. You can access them via the signatures directory which can be found in %AppData%\Roaming\Microsoft\Signatures – Sorceri Oct 01 '12 at 17:52
  • Yes, getting the files themselves is not the problem - finding the *correct* file based on the default signature is the problem. – Kevin Pope Oct 01 '12 at 18:07
  • This information is held in the registry. HCU\software\Microsoft\windows NT\Current Version\Windows Messaging Subsystem\Profiles\\ and then search for "Reply-Forward Signature". This is where that information is housed and it is a binary key. – Sorceri Oct 01 '12 at 20:27
0

I ended up solving this by creating a dictionary object with the key being the email address and the value as the filepath:

private Dictionary<string, string> signatureDictionary()
        {
            string sigDataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Microsoft\Signatures";
            Dictionary<string, string> returnValue = new Dictionary<string,string>();
            Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\9375CFF0413111d3B88A00104B2A6676", false);
            string[] str = key.GetSubKeyNames();
            foreach (string s in str)
            {
                Microsoft.Win32.RegistryKey subKey = key.OpenSubKey(s, false);
                if (subKey.GetValue("New Signature") != null)
                {
                    returnValue.Add(System.Text.Encoding.Unicode.GetString(subKey.GetValue("Account Name") as 
                        Byte[],0,(subKey.GetValue("Account Name") as Byte[]).Length - 2)
                        , Path.Combine(sigDataDir,System.Text.Encoding.Unicode.GetString(
                        subKey.GetValue("New Signature") as Byte[], 0, (subKey.GetValue("New Signature") as
                        Byte[]).Length - 2) + @".rtf"));
                }
            }
            key.Close();
            return returnValue;
        }

This answer to a similar question initially pointed me in the right direction, and figuring out that the "New Signature" key is only populated when a signature has been set for that account. Undoubtedly there will be situations where this doesn't work, but it sorts it out for my current issue. Since I use the WordEditor when I'm editing emails in VSTO I use the RTF files in this function, but there are also .HTM and .TXT files in the same directory so you can use those if you prefer.

Community
  • 1
  • 1
Kevin Pope
  • 2,964
  • 5
  • 32
  • 47