Script: Auto-generate Outlook Signature

If you’re managing a large number of users, you might sometimes have to create Outlook signatures for these users. Doing this manually can be a right pain in the arse, so I decided to write a quick script which, when executed (HINT: set it to run at logon in Group Policy), will automatically create a signature called ‘Default’ for Outlook 2003 and up to use. Disclaimer: I’ve only tested it on Outlook 2003 and Outlook 2007 running on a domain so if it doesn’t work, sorry…

Oh and yes, I am aware there are server-side and ASP products that can do this - however the only free product I’ve tried (GFI’s Mail Essentials) had a nasty habit of crashing our Exchange 2003 Server.


Set objUser = CreateObject("WScript.Network")
userName = objUser.UserName
domainName = objUser.UserDomain

FUNCTION GetUserDN(BYVAL UN, BYVAL DN)
Set ObjTrans = CreateObject("NameTranslate")
objTrans.init 1, DN
objTrans.set 3, DN & "\" & UN
strUserDN = objTrans.Get(1)
GetUserDN = strUserDN
END FUNCTION

Set objLDAPUser = GetObject("LDAP://" & GetUserDN(userName,domainName))

‘Prepare to create some files
Dim objFSO, objWsh, appDataPath, pathToCopyTo, plainTextFile,
plainTextFilePath, richTextFile, richTextFilePath, htmlFile,
htmlFilePath
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWsh = CreateObject("WScript.Shell")
appDataPath = objWsh.ExpandEnvironmentStrings("%APPDATA%")
pathToCopyTo = appDataPath & "\Microsoft\Signatures\"

‘Let’s create the plain text signature
plainTextFilePath = pathToCopyTo & "Default.txt"
Set plainTextFile = objFSO.CreateTextFile(plainTextFilePath, TRUE)
plainTextFile.WriteLine("– ")
plainTextFile.WriteLine(objLDAPUser.DisplayName)
plainTextFile.WriteLine(objLDAPUser.title)
plainTextFile.WriteLine(objLDAPUser.company)
plainTextFile.WriteLine("t: " & objLDAPUser.telephoneNumber)
plainTextFile.WriteLine("f: " & objLDAPUser.facsimileTelephoneNumber)
plainTextFile.WriteLine("e: " & objLDAPUser.mail)
plainTextFile.Write("w: " & objLDAPUser.wWWHomePage)
plainTextFile.Close

‘Now we create the Rich Text signature
richTextFilePath = pathToCopyTo & "Default.rtf"
Set richTextFile = objFSO.CreateTextFile(richTextFilePath, TRUE)
richTextFile.WriteLine("{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fswiss\fcharset0
Arial;}}")
richTextFile.WriteLine("\viewkind4\uc1\pard\f0\fs20 — \par")
richTextFile.WriteLine(objLDAPUser.DisplayName & "\par")
richTextFile.WriteLine(objLDAPUser.title & "\par")
richTextFile.WriteLine(objLDAPUser.company & "\par")
richTextFile.WriteLine("t: " & objLDAPUser.telephoneNumber & "\par")
richTextFile.WriteLine("f: " & objLDAPUser.facsimileTelephoneNumber & "\par")
richTextFile.WriteLine("e: " & objLDAPUser.mail & "\par")
richTextFile.WriteLine("w: " & objLDAPUser.wWWHomePage & "\par")
richTextFile.Write("}")
richTextFile.Close

‘And finally, the HTML signature
htmlFilePath = pathToCopyTo & "Default.htm"
Set htmlFile = objFSO.CreateTextFile(htmlFilePath, TRUE)
htmlfile.WriteLine("<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0
Transitional//EN""
""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">")
htmlfile.WriteLine("<html xmlns=""http://www.w3.org/1999/xhtml"" >")
htmlfile.WriteLine("<body>")
htmlfile.WriteLine("<div style=""font-size:10pt;
font-family:’Arial’,'helvetica’;"">")
htmlfile.WriteLine("<div>– </div>")
htmlfile.WriteLine("<div>" & objLDAPUser.DisplayName & "</div>")
htmlfile.WriteLine("<div>" & objLDAPUser.title & "</div>")
htmlfile.WriteLine("<div>" & objLDAPUser.company & "</div>")
htmlfile.WriteLine("<div>t: " & objLDAPUser.telephoneNumber & "</div>")
htmlfile.WriteLine("<div>f: " & objLDAPUser.facsimileTelephoneNumber & "</div>")
htmlfile.WriteLine("<div>e: <a href="" & objLDAPUser.mail & "">" &
objLDAPUser.mail & "</a></div>")
htmlfile.WriteLine("<div>w: <a href=""http://" &
objLDAPUser.wWWHomePage & """>" & objLDAPUser.wWWHomePage &
"</a></div>")
htmlfile.WriteLine("</div>")
htmlfile.WriteLine("</body>")
htmlfile.Write("</html>")


Google
 



This entry was posted on Wednesday, October 31st, 2007 at 3:53 pm and is filed under Windows. Find similar posts by selecting any of the following tags: . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

15 Comments so far

  1. When I execute it I receive an error,
    Expected identifier
    Line:16
    Char:62

  2. Ah… there are a few lines which, thanks to my stylesheet, are broken across several lines when they should be on one. Line breaks are very important to VBScript!

    Please go here to download the script in its working format.

    Rob

  3. Great script. I have one question. Rather than displaying t, f, e and w can it display, telephone, fax, email, website.
    Thanks!

  4. Ray,

    Yes. Just change t, f, e & w to telephone, fax, email & web. You can display anything you like inside the ” “. It’s a string.

    HTH

    Woter

  5. What exactly do I do with this file? Have it run with each individual logon? Sorry, I’m not very experienced with scripts.

  6. Thanks Rob, thats exactly what I have been looking for! :-)

    I would like to insert a company logo, could you point me in the right direction please?

    Thanks again!

    Al

  7. Hmm, that could be a lot more tricky. It should be pretty simple to do as a web link to an image hosted on a web site - just stick a line towards the end that says:

    htmlfile.WriteLine(”<div><img src=”http://your_image_path” /></div>”)

    If you’re trying to actually embed an image in the message however, you’d need to look at how Outlook does this internally. From memory it’s encoded as a binary MIME part; I’d suggest looking on the MSDN site if this is something you’d really want to do.

  8. Hi

    This is really good and thanks very much for providing this.

    Do u have any scripts for configuring Outlook profile?

  9. Hi

    Sorry if I’m being dim but how do you execute this? I’ve saving as a bat file and running it but I get an error on every line

  10. Sorry, ignore my last comment, I was being dim lol.

    One other question, how would I specify the font, size, and style of the rich text? I have searched the internet tirelessly for about an hour and a half and I can’t seem to find an answer.

    On our network all emails are either rich text or plain text (if sent or replied from a blackberry).

  11. Hi Steven,

    I’ve had a quick look at the RTF fonts thing. If you find the line that says:

    {\fonttbl{\f0\fswiss\fcharset0 Arial;}}
    You can extend this like so:

    {\fonttbl{\f0\fswiss\fcharset0 Arial;}{\f1\fswiss\fcharset1 FONT NAME HERE;}}

    You could add as many fonts as you liked (incrementing the "fx" each time). Then, wherever you want to use your new font, precede the line with \fx, as so:

    \f0 this text is in font f0, \f1 and this text will be in font f1

    I hope this makes sense!

    Rob

  12. Works great but how do you tell Outlook to use the Default signature for New messages and Replies/Forwards? It created it just fine but didn’t set it as the signature to use. I need that code if you know it.

  13. Hi
    That’s and excellent script!!!
    Here we have all auto generated mails. How to add signature with an Image on this?
    Is there any settings in Outlook or to go for Outlook macro.
    Guide me please, little bit an urgent assignment.

    Regards
    Yoganand

  14. Great script man! Can you help me in a small problem? I don’t know how to insert empty lines… i’m a script newbie :(
    I tried with htmlfile.writeline, but also writeblanklines but with no result…

  15. Fixed =) One of my collegues was a good html programmer… the solution is use the br tag.

    So… now only one question: the signature is created but not loaded automatically. How can i do this, if i can do this?

Have your say

Fields in bold are required. Email addresses are never published or distributed.

Some HTML code is allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
URIs must be fully qualified (eg: http://www.domainname.com) and all tags must be properly closed.

Line breaks and paragraphs are automatically converted.

Please keep comments relevant. Off-topic, offensive or inappropriate comments may be edited or removed.

  1. About Me

    Rob Whitehouse is an IT professional from Fulham in London, the UK. At work he specialises in systems architecture and large scale web infrastructures. He's an MCSE for Windows NT4 and 2003 as well as an MCITP: Windows 2008 Enterprise Admin and an MCTS: SQL Server 2005. He has also dabbled in Java, C# and pretty much every web-based language. Outside of work he can be found watching or playing sports, or in the local pub.
  2. Search

    Google
     
  3. Recent Posts

  4. Archives