Generating Outlook Signatures Based on Active Directory Information
(Page 1 of 4 )
Virtually all modern email clients support HTML-based emails, which means you can deliver a web page into people's mailboxes. While this brings up security issues, it also means we can make our email look a lot nicer than plain old text. Most people use this functionality to create an email signature. These normally provide contact information, web sites, company logos, etc. Many end users don’t have the necessary skills to create a nice looking email signature. This article will show you how to create one automatically.
We will use a VB Script to create an HTML file and populate this with information from the client's user object in the active directory. The HTML file will be saved into the user's Outlook signature folder, but you can use the same basic technique with any modern email client.
Getting started ... Connecting to the User object in the Active Directory
So, the first thing we need to do is connect to the client's user object in the active directory. This is surprisingly easy to do. First of all, we will create an object that points to the ADSystemInfo object. This object will give you some basic information about the currently logged in user.
The information in here is useful, but in our case it does not contain everything we need. What we can do, however, is use the ADSystemInfo.UserName property to open a connection to the active directory LDAP database, which is where the information we are after is held. So the first part of the script will look like this:
'create the objects and set the initial vars
Set WshShell = WScript.CreateObject("WScript.Shell")
Set FileSysObj = CreateObject("Scripting.FileSystemObject")
Set objADSysInfo = CreateObject("ADSystemInfo")
Set UserObj = GetObject("LDAP://" & objADSysInfo.UserName)
You have probably seen the first two lines before; they are creating objects (the shell and file system objects) we will use later.
The third and fourth lines are what we are using to connect to the active directory. First we are using the ADSystemInfo, and then, using the UserName property of that object, we can create a new object that binds to the client's user in the active directory.
Now that we have done that, we have access to all the information for the client, and we can use this information in our email signature. Next, the script will use our shell object to build some paths to where we are going to save the new signature file:
strAppData = WshShell.ExpandEnvironmentStrings("%APPDATA%")
SigFolder = StrAppData & "MicrosoftSignatures"
strQuteChr = chr(34)
SigFile = SigFolder & UserObj.sAMAccountName & ".htm"
These lines are just using the system environment variable APPDATA so that we know where to build the signature file. We then create an easy to remember variable for the double quote character, and set the name/path of our signature file to be the user's account name in the default signature folder.
Next: Checking for Existing Signature File >>
More Windows Scripting Articles
More By Luke Niland