HTML amd TXT email signatures from active directory

*** Please note this script was developed some years ago now and may not integrate as well with the latest versions of AD and Outlook. I am no longer troubleshooting any bugs with the script. Cheers, Cam ***

I created this script to build a simple html email signature based on a users data stored within active directory.

Setting devmode to true will cause the script to drop the signature files to the desktop for testing.

A user can have their mobile number omitted from the signature by adding a 'p' to the beginning of the Mobile field in active directory.

A few client details details have been chopped from the code and replaced with '####'

Source Code

This script has not been checked by Spiceworks. Please understand the risks before using it.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

'Switch for dev mode (true, false)DevMode=false'Default links for officesURLWWW="http://www.companyWebsite.com.au"sURLFacebook="http://www.facebook.com/companyFacebook"sURLTwitter="https://twitter.com/companyTwitter"sURLYoutube="http://www.youtube.com/companyYouTube"'Setup script functions for calls to file systemSetWshShell=WScript.CreateObject("WScript.Shell")SetFileSysObj=CreateObject("Scripting.FileSystemObject")strQuteChr=chr(34)ifDevModethenmsgbox"Devmode is ON"strDesktop=WshShell.SpecialFolders("Desktop")SigFolder=strDesktop&"\sigs\"SigFile=SigFolder&"sig_dev.htm"SigFileTxt=SigFolder&"sig_dev.txt"else'create the objects and set the initial varsSetobjADSysInfo=CreateObject("ADSystemInfo")SetUserObj=GetObject("LDAP://"&objADSysInfo.UserName)strAppData=WshShell.ExpandEnvironmentStrings("%APPDATA%")SigFolder=StrAppData&"\Microsoft\Signatures\"SigFile=SigFolder&UserObj.sAMAccountName&".htm"SigFileTxt=SigFolder&UserObj.sAMAccountName&".txt"EndIf'check the existence of the sig dir, if not there create itifnotFileSysObj.FolderExists(SigFolder)thenFileSysObj.CreateFolder(SigFolder)endififDevModethensUserName="dev"sFullName="Employee Full Name"sPosition="Employee Job Description"sMobile="0400 123 456"sEmail="email@yourdomain.com.au"sCompany="Company Name Pty Ltd"sOfficePhone="(03) 6300 1111"sOfficeFax="(03) 6300 2222"else'Get User Data from Active DirectorysUserName=UserObj.sAMAccountNamesFullName=UserObj.displaynamesPosition=UserObj.titlesMobile=UserObj.mobilesEmail=UserObj.mailsCompany=UserObj.companysOfficePhone=UserObj.telephoneNumbersOfficeFax=UserObj.facsimileTelephoneNumberendif'drop mobile number if personalifleft(sMobile,1)="p"thensMobile=""'create the htm file and start adding contentSetCreateSigFile=FileSysObj.CreateTextFile(SigFile,8,False)SetCreateSigFileTxt=FileSysObj.CreateTextFile(SigFileTxt,8,False)'html headCreateSigFile.WriteLine"<!DOCTYPE HTML PUBLIC "&"""-//W3C//DTD HTML 4.0 Transitional//EN"&""">"CreateSigFile.WriteLine"<HTML><HEAD><TITLE>Outlook Signature</TITLE>"CreateSigFile.WriteLine"<META http-equiv=Content-Style-Type content="&"""text/html; charset=windows-1252"""&">"CreateSigFile.WriteLine"<META content="&"""MSHTML 6.00.2900.3059"""&" name=GENERATOR>"CreateSigFile.WriteLine"<style type= text/css>"CreateSigFile.WriteLine"p {font-family:Calibri, Arial; font-size:11pt; color:#999; vertical-align:text-top;}"CreateSigFile.WriteLine".disclaimer {font-size:8pt; color:#999;}"CreateSigFile.WriteLine".name {font-size:11pt; color:#000}"CreateSigFile.WriteLine".title {font-size:11pt; color:#666;}"'CreateSigFile.WriteLine"</style></HEAD>"'html bodyCreateSigFile.WriteLine"<BODY>"CreateSigFile.WriteLine"<p><strong class="&"""name"&""">"&sFullName&"</strong><br>"CreateSigFile.WriteLine"<span class="&"""title"&""">"&sPosition&"</span><br>"CreateSigFile.WriteLine"<a href="&"""mailto:"&sEmail&""""&">"&sEmail&"</a>&nbsp; |&nbsp; "&sMobile&"</p>"CreateSigFile.WriteLine"<p><img src="&"""http://mail.####.com.au/sig/logo.jpg"&""" alt="&""""&""" width=312 height=50 border=0></p>"CreateSigFile.WriteLine"<p><strong>"&sCompany&"</strong><br>"CreateSigFile.WriteLine"Address Line 1<br>"CreateSigFile.WriteLine"Address Line 2<br>"CreateSigFile.WriteLine"P: "&sOfficePhone&"<br>"CreateSigFile.WriteLine"F: "&sOfficeFax&"</p>"CreateSigFile.WriteLine"<p><a href="&sURLFacebook&"><img src="&"""http://mail.####.com.au/sig/fb.jpg"&""" alt="&"""Facebook"&""" width=35 height=30 border=0></a>"CreateSigFile.WriteLine"<a href="&sURLTwitter&"><img src="&"""http://mail.####.com.au/sig/tw.jpg"&""" alt="&"""Twitter"&""" width=35 height=30 border=0></a>"CreateSigFile.WriteLine"<a href="&sURLYoutube&"><img src="&"""http://mail.####.com.au/sig/yt.jpg"&""" alt="&"""YouTube"&""" width=35 height=30 border=0></a>"CreateSigFile.WriteLine"<a href="&sURLWWW&"><img src="&"""http://mail.####.com.au/sig/www.jpg"&""" alt="&"""Website"&""" width=35 height=30 border=0></a></p>"CreateSigFile.WriteLine"<hr>"CreateSigFile.WriteLine"<p class="&"""disclaimer"&""">This email is intended for the use of the name individual or entity and may contain confidential and privileged information. Any dissemination, distribution or copying by anyone other than the intended recipient of this email is strictly prohibited. If this email has been received in error, please send an email in response, or telephone me immediately on ####, and destroy the original message. Any views expressed in this message are those of the individual sender, except where the sender specifically states them to be the views of ####.</p>"CreateSigFile.WriteLine"</BODY>"'close the signature fileCreateSigFile.CloseCreateSigFileTxt.WriteLinesFullNameCreateSigFileTxt.WriteLinesPositionifnotsMobile=""thenCreateSigFileTxt.WriteLinesMobile&" "&LCase(sEmail)elseCreateSigFileTxt.WriteLineLCase(sEmail)endifCreateSigFileTxt.WriteLine""CreateSigFileTxt.WriteLinesCompanyCreateSigFileTxt.WriteLine"Address"CreateSigFileTxt.WriteLinesOfficePhoneCreateSigFileTxt.WriteLinesURLWWWCreateSigFileTxt.WriteLine""CreateSigFileTxt.WriteLine""'close the txt signature fileCreateSigFileTxt.CloseifnotDevModethen'Set the signature as default for new and replySetobjWord=CreateObject("Word.Application")SetobjSignatureObjects=objWord.EmailOptions.EmailSignatureobjSignatureObjects.NewMessageSignature=sUserNameobjSignatureObjects.ReplyMessageSignature=sUserNameobjWord.QuitEndIf

Hi all,
I have tested the script and it works well.
Only one thing I have noticed, does outlook perform slower for anyone else except me?
It is slow during the initial laucn of outlook and a email template.
Very odd as it keeps saying "Contacting the server for information"
Any ideas?
Thanks

Hi CamboTas! Thank you very much for this script! Just what I was looking for and it works great!
I have one question regarding HTML encoding though. I have some special characters that are unable to show properly with standard charsets. The only way I can display them is using the HTML codes, but I have no idea how can I modify the script, that it will look up the HTML text after it's finished pulling data from AD, and then looking for specific chars and replace them with codes that I would set.
I was told it's possible to write inside the script, but no luck so far.
Thanks!

Although this is an old thread, I too was getting the "Automation Error" after trying to set the signature using the easy EmailSignature properties in Word.Application.EmailOptions. If this is the case for you then you need to catch the error in the block of code above ("if not devmode then...") and set the signature manually by editing the registry. There is a very good example of how to do this here: https://ifnotisnull.wordpress.com/automated-outlook-signatures-vbscript/the-script/
Specifically you will need the method "SetOutlookSig" and pass the sUserName as a parameter. I removed the log file parameter for that sub but you may find logging useful. You will also need the subsequent calls to other methods found in the SetOutlookSig sub (ie. String2ByteArray, String2Hex4, GetRegBinValue, SetRegValue).

Since I cannot edit my last post and add my rating...
I've almost made it perfect for our needs.
One last small issue is an error window, on some machines, right after you login, about that Outlook. username.ost is being used and cannot be accessed.
However I don't see anywhere, how this script touches the .ost file. Is simply just modifying signatures considered using .ost?