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>")
Advertisement
When I execute it I receive an error,
Expected identifier
Line:16
Char:62
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
Great script. I have one question. Rather than displaying t, f, e and w can it display, telephone, fax, email, website.
Thanks!
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
What exactly do I do with this file? Have it run with each individual logon? Sorry, I’m not very experienced with scripts.
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
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.
Hi
This is really good and thanks very much for providing this.
Do u have any scripts for configuring Outlook profile?
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
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).
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
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.
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
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…
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?
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.
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.
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.
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
[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?
Thanks a lot for sharing this, going to be testing it out and hopefully using it in our domain very soon :)
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”
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.
htmlfile.WriteLine(“”) [/CODE]
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.
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
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
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.
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 :(
There are no questions.
Simply I wish to tell many thanks.
Magnificent work.
Can you use windows variables within this script? i.e %username%
I am presuming that you can
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!
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(“”)
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?
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.
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
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
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
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!
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
This script is great.
Great job to those who made it!
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
Awesome piece of work, thank you!
Excellent !! Thanks…
Hi,
I am having issues with editing the html portion of this script to force bold, italics, and spaces between items .
htmlfile.WriteLine(“”)
I get this error for that line only:
Line: 69
Char: 33
Error: Expected ‘)’
Code: 800A03EE
Source: MS VBScript compilation error
What am I doing wrong? I have the script and the picture saved on my desktop.. not in seperate folders.
I’ve been using this script for over a year — it’s brilliant. I’ve created a GPO that runs it at logon and it’s been working perfectly, however, I’ve noticed it doesn’t work for my Windows 7-based machines at logon (but I can run it manually on Windows 7 and it works).
Don’t suppose anyone can think of a reason why?
I want to have different company logos based on the company name (Our company has several parts to it that are unique businesses under one corporate name) in ad. The attribute name is objLDAPUser.company. I was thinking of using If Then Else statements, but want to know how I’d add them in. Any pointers?
This is just to do text output, but will replace that with img source html tags once I get this part working.
if objLDAPUser.company = ‘Internal Services’ Then
htmlfile.WriteLine(‘Internal Services’) ElseIf
objLDAPUser.company = ‘Finance’ Then
htmlfile.WriteLine(‘Finance’) EndIf
You are by far a legend. You have saved us a lot of work!
Thank you!
Rob Great script
Thanks heaps for sharing this has saved me many hours/potential typos
Thanks to the other contributors as well
xiglet
“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. ”
This is because the Signarures folder is not there by default if a signature has not been configured as yet
Maybe someone can add a bit to the top of the script to check for and create the Signatures folder if is not already there
If it helps anyone I had to add 2 x graphics to the bottom sourced from and linked to a website, details have been changed
htmlfile.WriteLine(“”)
htmlfile.WriteLine(” “)
htmlfile.WriteLine(” “)
htmlfile.WriteLine(” “)
htmlfile.WriteLine(” “)
htmlfile.WriteLine(“”)
htmlfile.WriteLine(“”)
htmlfile.WriteLine(“”)
htmlfile.Write(“”)
Des
Rob,
I have created vbscipt similar to above for outlook signature. However I have a htm file with a letterhead stationary template. how would I go about writing script to set this within outlook 2003? Any help would be great
Hi All,
I need help to create auto reply to my office “help desk email”.
I want auto reply to happen between 5:01pm to 8:00 am then switched off during working hours *8:01am to 5:00pm everyday.
Thanks