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>")
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.
on Tuesday November 27 2007 at 5:02 pm noizychild wrote:
When I execute it I receive an error,
Expected identifier
Line:16
Char:62
on Friday November 30 2007 at 5:00 pm Rob wrote:
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
on Monday January 28 2008 at 1:16 pm Ray Ortiz wrote:
Great script. I have one question. Rather than displaying t, f, e and w can it display, telephone, fax, email, website.
Thanks!
on Thursday January 31 2008 at 1:05 pm Woter wrote:
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
on Thursday February 14 2008 at 6:24 pm Jason wrote:
What exactly do I do with this file? Have it run with each individual logon? Sorry, I’m not very experienced with scripts.
on Wednesday July 2 2008 at 10:01 am al wrote:
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
on Thursday July 17 2008 at 10:05 pm Rob wrote:
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.
on Tuesday July 29 2008 at 9:05 am vengadesh wrote:
Hi
This is really good and thanks very much for providing this.
Do u have any scripts for configuring Outlook profile?
on Tuesday August 12 2008 at 1:57 pm Steven wrote:
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
on Tuesday August 12 2008 at 3:54 pm Steven wrote:
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).
on Tuesday August 26 2008 at 12:06 pm Rob wrote:
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 f1I hope this makes sense!
Rob
on Wednesday October 8 2008 at 2:09 pm Jamie wrote:
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.
on Friday November 14 2008 at 3:46 am Yoganand wrote:
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
on Thursday November 20 2008 at 2:53 pm Enrico wrote:
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…
on Thursday November 20 2008 at 3:54 pm Enrico wrote:
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?