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: outlook, scripting. 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?
on Thursday, December 4, 2008 at 8:42 pm James wrote:
For those of you who want to set this automatically (Which, if you’re going to script it as a GPO, you will definitely want to) this is the solution, it may sound a bit silly, but hey, it’s VBS :)
You have create a Word object. For some reason, Microsoft have put all of the signature apis into Word, rather than Outlook. Just put in the following code:
Set objWord = CreateObject(“Word.Application”)
objWord.Visible = false
Set objEmailOptions = objWord.EmailOptions
Set objSignatureObject = objEmailOptions.EmailSignature
Set objSignatureEntries = objSignatureObject.EmailSignatureEntries
objSignatureObject.NewMessageSignature = “Default”
Change “Default” to the name of the file, if you have changed it.
I personally dislike full sized signatures in reply emails, so one extra thing I have done, is modified the above script (That you very much for that by the way, I didn’t realise you could use HTML, makes life so much easier.. I just have to figure out how to embed images now) to create two seperate files, one for new emails, and one for replies, and added the following line to my little snippet above:
objSignatureObject.ReplyMessageSignature = “Default – Reply”
Just copy and paste the “Now we create the Rich Text signature” and “And finally, the HTML signature” – changing the “Default.htm” and “Default.rtf” to “Default – Reply.htm” and “Default – Reply.rtf” and you’ll be set.
on Tuesday, December 23, 2008 at 4:08 pm Ian wrote:
There is some automated mail signature software out there called: Symprex Mail Signature Manager, it works with rtf, txt and html. Its very flexible, intregates into AD, pulling all it’s info from AD.
We have have used it for approx 6 months, allowing us to have standardised email signatures across our AD domain.
on Wednesday, January 28, 2009 at 5:56 pm Nuno Presley wrote:
Hi there,
This script would be very handy since I have to configure almost 150 signatures in a client company. They have several offices in several different cities so the solution would be to run something on each computer to generate the individual signature. Can this script be run in each Outlook client? Can anyone please explain how can we run this script, as many other users also have this doubt?
Thanks.
on Sunday, March 15, 2009 at 2:23 pm Rob wrote:
Hi Nuno,
The way I did it was via Group Policy. Create a GP object, open the scripts section, browse to the folder that is created for that GP for scripts, copy the .VBS file into this directory and link the GP to it. It’ll then run on every machine that gets the group policy applied to it.
Hope this helps,
Rob
on Friday, April 10, 2009 at 4:03 pm sysadmin wrote:
[quote]
For those of you who want to set this automatically (Which, if you’re going to script it as a GPO, you will definitely want to) this is the solution, it may sound a bit silly, but hey, it’s VBS :)
You have create a Word object. For some reason, Microsoft have put all of the signature apis into Word, rather than Outlook. Just put in the following code:
Set objWord = CreateObject(”Word.Application”)
objWord.Visible = false
Set objEmailOptions = objWord.EmailOptions
Set objSignatureObject = objEmailOptions.EmailSignature
Set objSignatureEntries = objSignatureObject.EmailSignatureEntries
objSignatureObject.NewMessageSignature = “Default”
Change “Default” to the name of the file, if you have changed it.
I personally dislike full sized signatures in reply emails, so one extra thing I have done, is modified the above script (That you very much for that by the way, I didn’t realise you could use HTML, makes life so much easier.. I just have to figure out how to embed images now) to create two seperate files, one for new emails, and one for replies, and added the following line to my little snippet above:
objSignatureObject.ReplyMessageSignature = “Default – Reply”
Just copy and paste the “Now we create the Rich Text signature” and “And finally, the HTML signature” – changing the “Default.htm” and “Default.rtf” to “Default – Reply.htm” and “Default – Reply.rtf” and you’ll be set.
[/quote]
I couldnt get this to work for me. I even declared the new variables. I can choose the signature but it doesnt automatically make it the default for new msgs or replies. Is it still working for you?
on Monday, June 29, 2009 at 1:33 pm Chris wrote:
Thanks a lot for sharing this, going to be testing it out and hopefully using it in our domain very soon :)
on Monday, July 20, 2009 at 7:31 pm Justin wrote:
If you need to set the default signature, and dont have Word installed on all your systems you can create a registry key that will set the default signatures.
Dim objWSHShell
Dim objWSHNetwork
Dim objLDAPUser
Dim strRegKey
Dim strNewSignature
Dim strReplySignature
Set objWSHShell = CreateObject(“WScript.Shell”)
Set objWSHNetwork = CreateObject(“WScript.Network”)
Set objLDAPUser = GetObject(“LDAP://” & GetUserDN(objWSHNetwork.UserName,objWSHNetwork.UserDomain))
strDisplayName = objLDAPUser.DisplayName
strRegKey = “HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Common\MailSettings\”
strNewSignature = strDisplayName
strReplySignature = strDisplayName & ” Reply”
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
objWSHShell.RegWrite strRegkey & “NewSignature”, strNewSignature , “REG_SZ”
objWSHShell.RegWrite strRegkey & “ReplySignature”, strReplySignature , “REG_SZ”
on Monday, July 20, 2009 at 9:16 pm Automatically creating outlook signatures using LDAP and a VB Login script « Shawson’s Code Blog wrote:
[...] [...]
on Tuesday, July 21, 2009 at 1:39 pm typhoon43 wrote:
I have had the GPO script working for some time now, but I CANNOT get a picture to embed (via link). We would like our company logo inserted but I can’t seem to make it happen. Not sure if it’s a limitation in Outlook 2007 or what. You original code for inserting an image errored on the tags. I removed them and the script runs without error, but still does not place the picture in the message. ANY help is appreciated. I’ve been Googling for 2 days now.
Current code for the image that doesn’t bomb, but doesn’t do anything either.
[code] htmlfile.WriteLine("") [/CODE]
on Tuesday, July 21, 2009 at 1:42 pm typhoon43 wrote:
Not sure what happened up there with the code. Again, I am using
htmlfile.WriteLine(” img src=”www.ourcompany.com./logo.jpg” />”)
to set the image. No errors, but it does not render at all.
< taken out before img src because it kept trying to run the code in this post.
on Sunday, July 26, 2009 at 6:43 pm Rob wrote:
Hi,
If you’re using “img src=”… the first ” will close the string file and ruin your HTML. For that line you should change it to something like this:
htmlfile.WriteLine(“img src=”"”http://www.ourcompany.com/logo.jpg”"” />”)
Hope this helps!
Rob
on Tuesday, August 11, 2009 at 3:32 pm karla wrote:
Helllo, thank you for the script, i How a question, how can I integrate the script for webmail , to the users that dont have outlook configure,
Thank you
on Wednesday, August 12, 2009 at 3:20 pm Rob wrote:
Unfortunately this is a client-only script, specifically for the Outlook client.
For webmail – OWA – I doubt very much it’s that straightforward as would probably require some custom ASPX forms in the OWA installation.
on Monday, August 17, 2009 at 3:14 pm Yogesh wrote:
Hello All,
I am also using the same script for auto signature but we are facing an issue from a quite long time now- users reported that when they login , they have the autosignature in outlook by defualt but after sometime they disappear of its own and they have to select it again form signature drop down menu.
I have pushed this vbs via group policy.
Please let me know wht can be done :(
on Friday, September 25, 2009 at 5:33 pm Vladimir wrote:
There are no questions.
Simply I wish to tell many thanks.
Magnificent work.
on Wednesday, September 30, 2009 at 3:54 pm Lee wrote:
Can you use windows variables within this script? i.e %username%
I am presuming that you can
on Tuesday, November 3, 2009 at 2:12 pm Sjouke wrote:
Thanks guys, by creating the script at my work my boss likes me because I saved € 1500,- :-)
But if anyone knows how to do it by OWA it would be perfect!
on Tuesday, November 10, 2009 at 4:06 pm Richard wrote:
For some reason I get the following error when running the basic script on a useraccount from a Active Directory policy:
permission denied: ‘createobject’ code 800A0046
Spent most of the day figuring this one out, still no clue…
Anyone want to share thoughts on this on? Thanx in advance!!
The script looks like this:
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\”
‘Create the plain text signature
plainTextFilePath = pathToCopyTo & “Default.txt”
Set plainTextFile = objFSO.CreateTextFile(plainTextFilePath, TRUE)
plainTextFile.WriteLine(objLDAPUser.DisplayName)
plainTextFile.WriteLine(objLDAPUser.title)
plainTextFile.WriteLine(“”)
plainTextFile.WriteLine(objLDAPUser.company)
plainTextFile.WriteLine(“”)
plainTextFile.WriteLine(“tel: ” & objLDAPUser.telephoneNumber)
plainTextFile.WriteLine(“fax: ” & objLDAPUser.facsimileTelephoneNumber)
plainTextFile.WriteLine(“mob: ” & objLDAPUser.mobile)
plainTextFile.WriteLine(“”)
plainTextFile.Write(objLDAPUser.wWWHomePage)
plainTextFile.WriteLine(“”)
plainTextFile.Close
‘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(“\par”)
richTextFile.WriteLine(objLDAPUser.company & “\par”)
richTextFile.WriteLine(“\par”)
richTextFile.WriteLine(“tel: ” & objLDAPUser.telephoneNumber & “\par”)
richTextFile.WriteLine(“fax: ” & objLDAPUser.facsimileTelephoneNumber & “\par”)
richTextFile.WriteLine(“mob: ” & objLDAPUser.mobile & “\par”)
richTextFile.WriteLine(“\par”)
richTextFile.WriteLine(objLDAPUser.wWWHomePage & “\par”)
richTextFile.WriteLine(“\par”)
richTextFile.Write(“}”)
richTextFile.Close
‘Create the HTML signature
htmlFilePath = pathToCopyTo & “Default.htm”
Set htmlFile = objFSO.CreateTextFile(htmlFilePath, TRUE)
htmlfile.WriteLine(“”)
htmlfile.WriteLine(“”)
htmlfile.WriteLine(“”)
htmlfile.WriteLine(“” & objLDAPUser.DisplayName & “”)
htmlfile.WriteLine(“” & objLDAPUser.title & “”)
htmlfile.WriteLine(“”)
htmlfile.WriteLine(“tel: ” & objLDAPUser.telephoneNumber & “”)
htmlfile.WriteLine(“fax: ” & objLDAPUser.facsimileTelephoneNumber & “”)
htmlfile.WriteLine(“mob: ” & objLDAPUser.mobile & “”)
htmlfile.WriteLine(“” & objLDAPUser.wWWHomePage & ““)
htmlfile.WriteLine(“”)
htmlfile.WriteLine(“”)
htmlfile.Write(“”)
on Monday, November 23, 2009 at 10:20 am Chris wrote:
Hi all,
First of all, I would like to thank the author for this script. It’s very good. In combination with some registry manipulation it’s quite powerful.
for me, there is only one question left. Since our firm’s signature is based on HTML, I would like to set Outlook’s Mail Format to HTML by default. Any idea where the proper registry entry looks can be found?
on Thursday, February 4, 2010 at 10:17 am CP wrote:
Hi, Great work on the script. Im a newb to this too but i have 1 more Q. I have 100 computer on the domain using outlook 2003 and signautres configured. Do you have a script that could run automatically for just 1 line of the signature which changes every 3 months. its really a pain to go edit all of these at once. Thanks again. really will appreciate the help.
on Thursday, February 11, 2010 at 10:03 am Mark wrote:
hi Rob,
this script works great on both rich text and plain, but i cant seem to get it working on html. I have done exaclty what you have.
could i have some advice?
Many thanks
on Wednesday, March 3, 2010 at 8:34 pm simon wrote:
Hi Rob,
please tell me about process for this script. I copied all codes and save into the stagging server but when I tried with same script then Its prompt “Run time error: Path not found” and same has been done into the XP machine with out member server machine “C:\WINDOWS\system32>cscript.exe //nologo sign.vbs
C:\WINDOWS\system32\sign.vbs(7, 1) (null): The specified domain either does not
exist or could not be contacted.”
Could you provide me steps to run this scripts. I just have little knowledge for script.
I really don’t know to how to run or where I need to keep this script and again how to run?
Could u help me?
Many Thanks ,
Simon D
on Tuesday, March 30, 2010 at 10:16 am xiglet wrote:
Hi
Looks just like what I’m looking for. However, I get this error:
Line: 24
Char: 1
Error: Path not found
Code: 800A004C
Source: Microsoft VBScript runtime error.
Any idea what causes this? I’m using a Windows7 client so I guessed the appdatapath could be wrong, but I get the same error on a Windows 2008 server.
best regards
xiglet
on Thursday, April 8, 2010 at 7:31 pm Mark C wrote:
Great script, thanks for creating this is at saved me many hours! One question, what is the proper syntax for the richtextfile if I wanted to have a line of text at the bottom in BOLD and with a font size of 7.5?
Thanks!
on Saturday, July 10, 2010 at 1:02 pm Andy D wrote:
Just to let you know, if you are not a developer/scripting wiz and want to do something like this for your user community, we have a low cost multi language compliant tool that you could consider, it also syncs with blackberry server as well.. Check it out here
http://www.iphelion.com/Product/SignatureCreator.aspx
Thanks
Andy
on Tuesday, July 27, 2010 at 10:07 pm Robert Findlay wrote:
This script is great.
Great job to those who made it!
on Tuesday, August 3, 2010 at 9:20 pm William wrote:
Great script and been working for a year or so now – but just recently 2 machines started getting “object does not support automation” error when running the script from gpo. It points to the following line:
objSignatureObject.NewMessageSignature = “Default”
anyone have any ideas?
the two workstations are running different versions of office (2007 and 2003)
TIA
William