Update: This article was updated on July 26, 2021.
In one of my previous articles, I showed how to create simple email signatures in Outlook using VBScript. In this article, I’ll show you how to take your email signatures to a higher level. I’m going to use VBScript to create an HTML email signature for each Outlook (for Windows) installation in your organization. The script creates a professional email signature with data from Active Directory. Next I will explain how to use GPO to distribute the script to all users in your organization.
Create HTML with VBScript
Before proceeding, a brief explanation of how to create an HTML file using VBScript. Both VBScript and HTML languages use double quotation marks (“) as the standard character for specifying data entry. That creates a problem, at least in this scenario. If you try to use single quotes for data entry in VBScript, you’ll end up turning the entire script into one giant comment. There are two methods we can use to work around this problem:
- Add to & “”” after each double quote in the HTML code (method used in Script 1). Just make sure you include a space before the & character as well.
- Change all double quotes to single quotes in HTML code (method used in Script 2).
I prefer method 2 because it results in cleaner code and it’s easy to use e.g. Notepad to replace all ” with ‘ in a source HTML file.
In addition to these methods, you could use just a single WriteLine method and create a single line of HTML. Although the method used in Script 2 might make it a bit easier, it will seriously affect the readability of your code.
Sample VBScripts
First you need to create a script that creates a personalized HTML email signature for each user. In the following I present two different example scripts that create two different signature templates. These examples use slightly different methods of generating HTML code.
The base HTML code for signature templates comes from the Free email signature generator.
Important! Both scripts contain a section with global placeholders. They refer to data that should be the same for each user (company address, social media sites, etc.). Be sure to replace their values with your company’s data.
script 1
Using the first example script, you can create the following signature template:
Click to expand/collapse Script 1
On Error Resume Next 'Setting up the script to work with the file system. Set WshShell = WScript.CreateObject("WScript.Shell") Set FileSysObj = CreateObject("Scripting.FileSystemObject") 'Connecting to Active Directory to get user’s data. Set objSysInfo = CreateObject("ADSystemInfo") Set UserObj = GetObject("LDAP://" & objSysInfo.UserName) strAppData = WshShell.ExpandEnvironmentStrings("%APPDATA%") SigFolder = StrAppData & "\Microsoft\Signatures\" SigFile = SigFolder & UserObj.sAMAccountName & "1.htm" 'Setting placeholders for the signature. strUserName = UserObj.sAMAccountName strFullName = UserObj.displayname strTitle = UserObj.title strMobile = UserObj.mobile strEmail = UserObj.mail strCompany = UserObj.company strOfficePhone = UserObj.telephoneNumber 'Setting global placeholders for the signature. Those values will be identical for all users - make sure to replace them with the right values! strCompanyLogo = """https://codetwocdn.azureedge.net/images/mail-signatures/generator-dm/simplephoto-with-logo/logo.png" strCompanyAddress1 = "16 Freedom St, Deer Hill" strCompanyAddress2 = "58-500 Poland" strWebsite = """https://www.my-company.com" strFacebook = """https://www.facebook.com/" strTwitter = """https://www.twitter.com/" strYouTube = """https://www.youtube.com/" strLinkedIn = """https://www.linkedin.com/" strInstagram = """https://www.instagram.com/" strPinterest = """https://www.pinterest.com/" 'Creating HTM signature file for the user's profile, if the file with such a name is found, it will be overwritten. Set CreateSigFile = FileSysObj.CreateTextFile (SigFile, True, True) 'Signature’s HTML code. CreateSigFile.WriteLine "<!DOCTYPE HTML PUBLIC " & """-//W3C//DTD HTML 4.0 Transitional//EN" & """>" CreateSigFile.WriteLine "<HTML><HEAD><TITLE>Email Signature</TITLE>" CreateSigFile.WriteLine "<META content=" & """text/html; charset=utf-8" & """ http-equiv=" & """Content-Type" & """>" CreateSigFile.WriteLine "</HEAD>" CreateSigFile.WriteLine "<BODY style=" & """font-size: 10pt; font-family: Arial, sans-serif;" & """>" CreateSigFile.Writeline "<table style=" & """width: 420px; font-size: 10pt; font-family: Arial, sans-serif;" & """ cellpadding=" & """0" & """ cellspacing=" & """0" & """>" CreateSigFile.Writeline "<tbody>" CreateSigFile.Writeline "<tr>" CreateSigFile.Writeline "<td width=" & """130" & """ style=" & """font-size: 10pt; font-family: Arial, sans-serif; border-right: 1px solid; border-right-color: #008080; width: 130px; padding-right: 10px; vertical-align: top;" & """ valign=" & """top" & """ rowspan=" & """6" & """> <a href="https://www.codetwo.com/admins-blog/vbscript-create-an-html-outlook-email-signature-for-the-whole-company/& strWebsite &""" target=" & """_blank" & """><img border=" & """0" & """ alt=" & """Logo" & """ width=" & """110" & """ style=" & """width:110px; height:auto; border:0;" & """ src=" & strCompanyLogo & """></a>" CreateSigFile.Writeline "</td>" CreateSigFile.Writeline "<td>" CreateSigFile.Writeline "<table cellpadding="& """0"& """ cellspacing="& """0"& """>" CreateSigFile.Writeline "<tbody>" CreateSigFile.Writeline "<tr>" CreateSigFile.Writeline "<td style="& """font-size: 10pt; color:#0079ac; font-family: Arial, sans-serif; width: 305px; padding-bottom: 5px; padding-left: 10px; vertical-align: top; line-height:25px;"& """ valign="& """top"& """>" CreateSigFile.Writeline "<strong><span style="& """font-size: 14pt; font-family: Arial, sans-serif; color:#008080;"& """>" & strFullName & "<br></span></strong>" CreateSigFile.Writeline "<span style="& """font-family: Arial, sans-serif; font-size:10pt; color:#545454;"& """>" & strTitle & "</span>" CreateSigFile.Writeline "<span style="& """font-family: Arial, sans-serif; font-size:10pt; color:#545454;"& """> | </span>" CreateSigFile.Writeline "<span style="& """font-family: Arial, sans-serif; font-size:10pt; color:#545454;"& """>" & strCompany & "</span>" CreateSigFile.Writeline "</td>" CreateSigFile.Writeline "</tr>" CreateSigFile.Writeline "<tr>" CreateSigFile.Writeline "<td style="& """font-size: 10pt; color:#444444; font-family: Arial, sans-serif; padding-bottom: 5px; padding-top: 5px; padding-left: 10px; vertical-align: top;"& """ valign="& """top"& """>" CreateSigFile.Writeline "<span><span style="& """color: #008080;"& """><strong>m:</strong></span><span style="& """font-size: 10pt; font-family: Arial, sans-serif; color:#545454;"& """>" & strMobile & "<br></span></span>" CreateSigFile.Writeline "<span><span style="& """color: #008080;"& """><strong>p:</strong></span><span style="& """font-size: 10pt; font-family: Arial, sans-serif; color:#545454;"& """>" & strOfficePhone & "<br></span></span>" CreateSigFile.Writeline "<span><span style="& """color: #008080;"& """><strong>e:</strong></span><span style="& """font-size: 10pt; font-family: Arial, sans-serif; color:#545454;"& """>" & strEmail& "</span></span>" CreateSigFile.Writeline "</td>" CreateSigFile.Writeline "</tr>" CreateSigFile.Writeline "<tr>" CreateSigFile.Writeline "<td style="& """font-size: 10pt; font-family: Arial, sans-serif; padding-bottom: 5px; padding-top: 5px; padding-left: 10px; vertical-align: top; color: #0079ac;"& """ valign="& """top"& """>" CreateSigFile.Writeline "<span style="& """font-size: 10pt; font-family: Arial, sans-serif; color: #008080;"& """>" & strCompanyAddress1 & "<span><br></span></span>" CreateSigFile.Writeline "<span style="& """font-size: 10pt; font-family: Arial, sans-serif; color: #008080;"& """>" & strCompanyAddress2 &"</span>" CreateSigFile.Writeline "</td>" CreateSigFile.Writeline "</tr>" CreateSigFile.Writeline "<tr>" CreateSigFile.Writeline "<td style="& """font-size: 10pt; font-family: Arial, sans-serif; padding-bottom: 5px; padding-top: 5px; padding-left: 10px; vertical-align: top; color: #0079ac;"& """ valign="& """top"& """>" CreateSigFile.Writeline "<a href="& """https://www.my-company.com"& """ target="& """_blank"& """ rel="& """noopener"& """ style="& """text-decoration:none;"& """><span style="& """font-size: 10pt; font-family: Arial, sans-serif; color: #008080;"& """>www.my-company.com</span></a>" CreateSigFile.Writeline "</td>" CreateSigFile.Writeline "</tr>" CreateSigFile.Writeline "<tr>" CreateSigFile.Writeline "<td style="& """font-size: 10pt; font-family: Arial, sans-serif; padding-bottom: 5px; padding-top: 5px; padding-left: 10px; vertical-align: top;"& """ valign="& """top"& """>" CreateSigFile.Writeline "<span><a href="& strFacebook & """ target="& """_blank"& """ rel="& """noopener"& """><img border="& """0"& """ width="& """21"& """ alt="& """facebook icon"& """ style="& """border:0; height:21px; width:21px"& """ src="& """https://codetwocdn.azureedge.net/images/mail-signatures/generator-dm/simplephoto-with-logo/fb.png"& """></a> </span><span><a href="& strTwitter & """ target="& """_blank"& """ rel="& """noopener"& """><img border="& """0"& """ width="& """21"& """ alt="& """twitter icon"& """ style="& """border:0; height:21px; width:21px"& """ src="& """https://codetwocdn.azureedge.net/images/mail-signatures/generator-dm/simplephoto-with-logo/tt.png"& """></a> </span><span><a href="& strYouTube & """ target="& """_blank"& """ rel="& """noopener"& """><img border="& """0"& """ width="& """21"& """ alt="& """youtube icon"& """ style="& """border:0; height:21px; width:21px"& """ src="& """https://codetwocdn.azureedge.net/images/mail-signatures/generator-dm/simplephoto-with-logo/yt.png"& """></a> </span><span><a href="& strLinkedIn & """ target="& """_blank"& """ rel="& """noopener"& """><img border="& """0"& """ width="& """21"& """ alt="& """linkedin icon"& """ style="& """border:0; height:21px; width:21px"& """ src="& """https://codetwocdn.azureedge.net/images/mail-signatures/generator-dm/simplephoto-with-logo/ln.png"& """></a> </span><span><a href="& strInstagram & """ target="& """_blank"& """ rel="& """noopener"& """><img border="& """0"& """ width="& """21"& """ alt="& """instagram icon"& """ style="& """border:0; height:21px; width:21px"& """ src="& """https://codetwocdn.azureedge.net/images/mail-signatures/generator-dm/simplephoto-with-logo/it.png"& """></a> </span><span><a href="& strPinterest & """ target="& """_blank"& """ rel="& """noopener"& """><img border="& """0"& """ width="& """21"& """ alt="& """pinterest icon"& """ style="& """border:0; height:21px; width:21px"& """ src="& """https://codetwocdn.azureedge.net/images/mail-signatures/generator-dm/simplephoto-with-logo/pt.png"& """></a></span>" CreateSigFile.Writeline "</td>" CreateSigFile.Writeline "</tr>" CreateSigFile.Close 'Applying the signature in Outlook’s settings. Set objWord = CreateObject("Word.Application") Set objSignatureObjects = objWord.EmailOptions.EmailSignature 'Setting the signature as default for new messages. objSignatureObjects.NewMessageSignature = strUserName & "1" 'Setting the signature as default for replies & forwards. objSignatureObjects.ReplyMessageSignature = strUserName & "1" objWord.Quit
script 2
You can use the following script to create the following signature template:
Click to expand/collapse Script 2
On Error Resume Next 'Setting up the script to work with the file system. Set WshShell = WScript.CreateObject("WScript.Shell") Set FileSysObj = CreateObject("Scripting.FileSystemObject") Set objSysInfo = CreateObject("ADSystemInfo") Set UserObj = GetObject("LDAP://" & objSysInfo.UserName) strAppData = WshShell.ExpandEnvironmentStrings("%APPDATA%") SigFolder = StrAppData & "\Microsoft\Signatures\" SigFile = SigFolder & UserObj.sAMAccountName & "2" & ".htm" 'Setting placeholders for the signature. They will be automatically replaced with data from Active Directory. strUserName = UserObj.sAMAccountName strFullName = UserObj.displayname strTitle = UserObj.title strMobile = UserObj.mobile strEmail = UserObj.mail strCompany = UserObj.company strOfficePhone = UserObj.telephoneNumber 'Setting global placeholders for the signature. Those values will be identical for all users - make sure to replace them with the right values! strCompanyLogo = "https://codetwocdn.azureedge.net/images/mail-signatures/generator-dm/hexagonal-logo/logo.png" strBanner = "https://codetwocdn.azureedge.net/images/mail-signatures/generator-dm/hexagonal-logo/banner.png" strBannerLinkingTo = "https://www.codetwo.com/email-signatures/" strCompanyAddress = "16 Freedom St, Deer Hill 58-500 Poland" strWebsite = "www.my-company.com" strFacebook = "https://www.facebook.com/" strTwitter = "https://www.twitter.com/" strYouTube = "" strLinkedIn = "https://www.linkedin.com/" strInstagram = "https://www.instagram.com/" strPinterest = "" 'Creating HTM signature file for the user's profile. Set CreateSigFile = FileSysObj.CreateTextFile (SigFile, True, True) 'Signature’s HTML code CreateSigFile.WriteLine "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'>" CreateSigFile.WriteLine "<HTML><HEAD><TITLE>Email Signature</TITLE>" CreateSigFile.WriteLine "<META content="text/html; charset=utf-8" http-equiv='Content-Type'>" CreateSigFile.WriteLine "</HEAD>" CreateSigFile.WriteLine "<BODY style="font-size: 10pt; font-family: Arial, sans-serif;">" CreateSigFile.WriteLine "<table width="480" style="font-size: 11pt; font-family: Arial, sans-serif;" cellpadding='0' cellspacing='0' border="0">" CreateSigFile.WriteLine "<tbody>" CreateSigFile.WriteLine "<tr>" CreateSigFile.WriteLine "<td width="160" style="font-size: 10pt; font-family: Arial, sans-serif; width: 160px; vertical-align: top;" valign='top'> <a href="https://www.my-company.com/" target="_blank"><img border="0" alt="Logo" width="125" style="width:125px; height:auto; border:0;" src="" & strCompanyLogo & ""></a>" CreateSigFile.WriteLine "</td>" CreateSigFile.WriteLine "<td valign='top' width="270" style="width:270px; vertical-align: top; line-height:11px; border-right:2px solid #29abe1"><table cellpadding='0' cellspacing='0' border="0" width="270"><tbody> <tr> <td style="font-size:12pt; height:14px; line-height:14px"><strong style="font-family: Arial, sans-serif;font-size: 12pt;color:#29abe1;">" & strFullName & "</strong></td> </tr> <tr> <td style="font-size:9pt; height:14px; line-height:14px"> <span style="font-family: Arial, sans-serif; font-size:9pt; color:#000000;">" & strTitle & "</span> <span style="font-family: Arial, sans-serif; font-size:9pt; color:#000000;"> |" & strCompany & "</span> </td> </tr> <tr> <td style="height:14px; line-height:14px"> </td> </tr> <tr> <td style="font-size:9pt; height:14px; line-height:14px"> <span style="font-family: Arial, sans-serif;color:#000000;FONT-SIZE: 9pt"><strong>M</strong> " & strMobile & "</span> <span style="font-family: Arial, sans-serif;color:#000000;FONT-SIZE: 9pt"> | <strong>P</strong> " & strOfficePhone & "</span> </td> </tr> <tr> <td style="font-size:9pt; height:12px; line-height:12px"> <span style="font-family: Arial, sans-serif;color:#000000;FONT-SIZE: 9pt"><strong>E</strong> " & strEmail & "</span> </td> </tr> <tr> <td style="height:14px; line-height:14px"> </td> </tr> <tr> <td style="font-size:9pt; height:12px; line-height:12px"> <span style="font-family: Arial, sans-serif;color:#000000;FONT-SIZE: 9pt">" & strCompanyAddress & "</span> </td> </tr> <tr> <td style="font-size:9pt; height:12px; line-height:12px"> <span><a href="https://"https://www.codetwo.com/admins-blog/vbscript-create-an-html-outlook-email-signature-for-the-whole-company/& strWebsite &"" target="_blank" rel="noopener" style=" text-decoration:none;"><strong style="color:#29abe1; font-family:Arial, sans-serif; font-size:9pt">"https://www.codetwo.com/admins-blog/vbscript-create-an-html-outlook-email-signature-for-the-whole-company/& strWebsite &"</strong></a></span> </td> </tr> </tbody><tbody> </tbody></table>" CreateSigFile.WriteLine "</td>" CreateSigFile.WriteLine "<td style="vertical-align: top; padding-left:10px" valign='top' width="35"> <table cellpadding='0' cellspacing='0' border="0" width="25"> <tbody>" If strFacebook <> "" Then CreateSigFile.WriteLine "<tr> <td width="25" height="30" valign='top' style="vertical-align: top;"><a href="" & strFacebook & "" target="_blank" rel="noopener"><img border="0" width="26" height="25" alt="facebook icon" style="border:0; height:25px; width:26px;" src="https://codetwocdn.azureedge.net/images/mail-signatures/generator-dm/hexagonal-logo/fb.png"></a></td></tr>" End If If strTwitter <> "" Then CreateSigFile.WriteLine "<tr> <td width="25" height="30" valign='top' style="vertical-align: top;"><a href="" & strTwitter & "" target="_blank" rel="noopener"><img border="0" width="26" height="25" alt="twitter icon" style="border:0; height:25px; width:26px;" src="https://codetwocdn.azureedge.net/images/mail-signatures/generator-dm/hexagonal-logo/tt.png"></a></td></tr>" End If If strYouTube <> "" Then CreateSigFile.WriteLine "<tr> <td width="25" height="30" valign='top' style="vertical-align: top;"><a href=""& strYouTube &"" target="_blank" rel="noopene r"><img border="0" width="26" height="25" alt="youtube icon" style="border:0; height:25px; width:26px" src="https://codetwocdn.azureedge.net/images/mail-signatures/generator-dm/hexagonal-logo/yt.png"></a></td> </tr>" End If CreateSigFile.WriteLine "</tbody></table>" CreateSigFile.WriteLine "</td>" CreateSigFile.WriteLine "<td style="vertical-align: top;" valign='top' width="25">" CreateSigFile.WriteLine "<table cellpadding='0' cellspacing='0' border="0" width="25"> <tbody>" If strLinkedIn <> "" Then CreateSigFile.WriteLine "<tr><td style="height:12px; font-size:1px" height="12"> </td></tr> <tr> <td width="25" height="30" valign='top' style="vertical-align: top;"><a href="" & strLinkedIn & "" target="_blank" rel="noopener"><img border="0" width="26" height="25" alt="linkedin icon" style="border:0; height:25px; width:26px;" src="https://codetwocdn.azureedge.net/images/mail-signatures/generator-dm/hexagonal-logo/ln.png"></a></td> </tr>" End If If strInstagram <> "" Then CreateSigFile.WriteLine "<tr> <td width="25" height="30" valign='top' style="vertical-align: top;"><a href="" & strInstagram & "" target="_blank" rel="noopener"><img border="0" width="26" height="25" alt="instagram icon" style="border:0; height:25px; width:26px;" src="https://codetwocdn.azureedge.net/images/mail-signatures/generator-dm/hexagonal-logo/it.png"></a></td> </tr>" End If If strPinterest <> "" Then CreateSigFile.WriteLine "<tr> <td width="25" height="30" valign='top' style="vertical-align: top;"><a href="" & strPinterest & "" target="_blank" rel="noopener"><img border="0" width="26" height="25" alt="pinterest icon" style="border:0; height:25px; width:26px" src="https://codetwocdn.azureedge.net/images/mail-signatures/generator-dm/hexagonal-logo/pt.png"></a></td> </tr>" End If CreateSigFile.WriteLine "</tbody></table>" CreateSigFile.WriteLine "</td>" CreateSigFile.WriteLine "</tr>" CreateSigFile.WriteLine "<tr><td colspan='4' style="padding-top:15px;"> <a href="" & strBannerLinkingTo & "" target="_blank" rel="noopener"><img border="0" alt="Banner" width="479" style="max-width:479px; height:auto; border:0;" src="" & strBanner & ""></a> </td>" CreateSigFile.WriteLine "</tr>" CreateSigFile.WriteLine "<tr><td colspan='4' style="padding-top:15px; line-height:14px; font-size: 7.5pt; color: #808080; font-family: Arial, sans-serif;">The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to share any part of this message with any third party, without a written consent of the sender. If you received this message by mistake, please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.</td>" CreateSigFil CreateSigFile.WriteLine "</tbody>" CreateSigFile.WriteLine "</table>" CreateSigFile.WriteLine "</BODY>" CreateSigFile.WriteLine "</HTML>" CreateSigFile.Close Set objWord = CreateObject("Word.Application") Set objSignatureObjects = objWord.EmailOptions.EmailSignature objSignatureObjects.NewMessageSignature = strUserName & "2" objSignatureObjects.ReplyMessageSignature = strUserName & "2" objWord.Quit
Create your own script
You can add any HTML signature to the VBScript. For good examples of HTML signature templates, see Free email signature generator or the Free signature template library.
The general idea for creating your own script using the sample scripts provided in the previous section of this article is to replace the code below the ‘HTML code of the signature comment with your own. Remember to replace user-specific data with wildcards, for example use strFullName instead of the username.
If you’re using the free email signature generator, you can remove the global placeholders found in the script above. Simply provide your company details and any necessary links and graphics in the generator instead of replacing them with global placeholders in the HTML code.
Deploy the script to a single user
Before running the script on everyone in your organization, it’s best to test it on a single user. Whether it’s your custom script or one of the examples provided above, follow these simple steps to deploy the script:
- Copy and paste the VBScript code into a plain text editor (such as Notepad or Notepad++).
- Substitute values for global placeholders (if applicable).
- Save the file with a .vbs extension.
- Run the script by double-clicking the VBS file.
- Finally go to outlook > file > options > post Office > signatures and confirm if a signature with the same name as your AD account name has been added to the list of available signatures.
Now if you get to the signature settings you may see that the graphics are flattened like this:
This is because Outlook’s signature editor doesn’t parse HTML very well. The problem arises because the graphics height is set to “auto”. Fortunately, the signature is correctly parsed when added to an email.
Deploy the script to multiple users
There are two easy ways to deploy the script to multiple users. One is to launch the VBS file from any workstation, the second is to use GPO and a login script. Since the first method is self-explanatory, I’ll show how to deploy the signature using GPO.
The next time a user logs in, the signature script should run and the email signature should be added to that user’s Outlook profile.
Professional management of email signatures
With VBScript and GPO you can manage e-mail signatures company-wide. Thanks to this method, you can successfully provide unified email signatures to every Outlook user in your organization. As nice as it is, the method is not perfect. Here are just some of its disadvantages:
- requires at least basic scripting knowledge,
- does not work with email clients other than desktop Outlook for Windows,
- does not prevent users from changing the signature,
- Updates take time (you need to change the script and redistribute),
- It is impossible to delegate this task to a marketing team,
- If for some reason the script doesn’t work in your environment (e.g. you’re using a non-standard port to communicate with LDAPS), you’re on your own to troubleshoot.
For this reason we have developed tools for managing email signatures. The product family CodeTwo Exchange Rules (for Exchange Server versions from 2007 to 2019) and CodeTwo Email Signatures for Office 365 (for Microsoft 365 organizations) take email signature management to a whole other level. With these tools you can:
- Design email signatures with a simple WYSIWYG editor or simply import any HTML code.
- Add email signatures to emails sent from any email client or device (including mobile phones).
- Add different email signature templates for different scenarios (depending on the recipient, different signatures for first and subsequent emails in a conversation thread).
- Prevent users from making changes to the signature or disclaimer.
- Implement changes to signatures immediately (changing images).
- Embed images so they’re always visible to your recipients (without having to click Download Images).
- Plan marketing campaigns.
- Stay calm knowing that a 24/5 customer success team is at your disposal should you encounter any issues.
- And benefit from many other features…
Try CodeTwo Email Signatures for Office 365 for free – If you have a Microsoft 365 organization.
Try CodeTwo Exchange Rules for free – if you run a local Exchange Server.