8

i made something to generate the signatures for users, but now i would also like to set it as default signature. this will it will be automaticly added to new emails you are writing or answering.

i have not been able to find any kind of example or reference to how i could do this. Can someone point me in the right direction please.

Kage
  • 486
  • 1
  • 7
  • 18
  • try this [add signature](http://stackoverflow.com/questions/6442747/add-the-default-outlook-signature-in-the-email-generated) – PresleyDias Jun 07 '12 at 10:33
  • @PresleyDias Thanks for the reply, however im trying to set the setting in outlook for what the default signature is. – Kage Jun 07 '12 at 10:39
  • meaning you want to change Outlook's signature from the current one? – PresleyDias Jun 07 '12 at 10:48

2 Answers2

9

I find it more easy to set the signatures through the VSTO Word object:

 static void SetDefault(string signature)
    {
        Word.Application oWord = new Word.Application();
        Word.EmailOptions oOptions;
        oOptions = oWord.Application.EmailOptions;
        oOptions.EmailSignature.NewMessageSignature = signature;
        oOptions.EmailSignature.ReplyMessageSignature = signature;
        //Release Word
        if (oOptions != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(oOptions);
        if (oWord != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord);


    }
MortenF
  • 115
  • 2
  • 6
  • You can also do this using the VBA Word object, in the same way as above – Niall Jun 26 '14 at 11:46
  • Simple, much better than messing with the registry. Thanks. – CrazyTim Jul 20 '15 at 00:25
  • Isn't "Outlook.Application oApplication = ThisAddIn.app;" useless ? I'm a bit lost about how it's suppose to work... – Thibault Gandon Jul 28 '17 at 15:47
  • Yes, you'e right (it's a snip from a method within an Outlook add-in) You don't need the app object for this. I've edited the post. – MortenF Jul 30 '17 at 21:20
  • This works. Need to keep the signature file (like sig.htm) in `Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Microsoft\\Signatures"` folder. Also, pass just the filename without extension (".htm") to the function `SetDefault("sig");` – sameerkn Jul 21 '20 at 13:47
2

Found a way to do this with a registry key. the key is located at HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows messaging Subsystem\Profiles[OutlookProfilename]\9375CFF0413111d3B88A00104B2A6676

in that key there will me mutitple folder 00000001 going up, for each signature one. if you delete someone's windows profile the count starts at 1 again.

in here if you place a REG_Binary named "New Signature" or "Reply-Forward Signature" the value should be the name of the signature in hex format. Say the signatures name is Test it would become
54 65 73 74 in hex. the reg key would like it like this:
54006500730074000000000000000000000000

i hope i made myself clear like this :D it wasnt easy finding this :D

Kage
  • 486
  • 1
  • 7
  • 18
  • 1
    Keep in mind that this will not work in general - 9375CFF0413111d3B88A00104B2A6676 is the profile section GUID that will differ for different profiles and on different machines. – Dmitry Streblechenko Sep 04 '15 at 06:23