Kewl Code: Automated Signature Block Wizard
Category Technical
Bookmark :
I use a signature block on my emails that are sent from my IBM address. I created it when I joined, and I use the nice feature found on the Signature tab of the Preferences in my mail file to include an HTML file as my signature. Works great. I was talking to Kristin Keene (Queen-of-all-that-is-content at Lotusphere) about Lotusphere, and she mentioned that she really liked my signature block. Because Kristin is my friend, I whipped one up for her that looks like the example in the graphic above (of course I have shrunk and blurred that graphic, but you get the idea). She was ecstatic - and then asked if there was a way to automate it so that her staff could have sig blocks with links that advertise Lotusphere 2006. She wanted simply a template with instructions on how they could edit it and add it manually themselves.
Silly lady, she doesn't know that a geek like me cannot pass up the opportunity to automate something like this!
So, I set out to create an automated Signature Block Wizard. Before I began I had to define the parameters of this little "toolet":
- It has to be mailable - so all of the files and code has to be able to be contained in a single mail memo
- It has to be easy - it needs to simply ask them some questions about their identity, and do all the work for them
- Simplicity means it needed to automatically update the file and detach it and the graphic file into the appropriate directories
- Simplicity also means that it needs to modify their Mail Preferences to enable the signature feature and point it to the newly created file
So this "toolet" needs to ask them some questions and then simply "work" the next time they compose an email.
Design
The signature is comprised of two files - the HTML file containing the code (and style info, I use CSS), and the graphic at the bottom. I realized that I could either create the HTML file on the fly each time, or I could have an existing template and simply search/replace on special "tags" to add the user ID info. I decided on the latter, beause it was easier to do overall.
The entire toolet is three parts: the graphic file, the HTML file, and a button in the email that does the work. Let's take a look at the button code...
Button Code
I was going to post all of the button code, but there seems to be a bug in my beta version of Blogpshere that prevents me from adding too much text to a post ("field is too large" error when I try to save). So, instead I have attached a link to the button code as an LSS (sig_wizard.lss), and you can import it into a button and follow along. I will reproduce the "good stuff" below, with an explanation.
userdir = Environ("USERPROFILE") ' windows user dir
sigpath = userdir & "\My Documents"
sigpicpath = sigpath & "\My Pictures\LotusBar.jpg"
sigpath = sigpath & "\my_sig.htm"
This little bit bit gets the beginning of the path to the user's My Documents directory. The USERPROFILE Win environment variable returns the path to the user's profile directory, e.g. "C:\Documents and Settings\Rock" for me.
REM set up user info list
userinfo("name") = "Your Name"
userinfo("title") = "Grand Poobah"
userinfo("phone") = "212.555.1212"
userinfo("tie-line") = "316.1212"
userinfo("fax") = "212.555.1313"
userinfo("link url") = "http://www.ibm.com/lotus/lotusphere"
userinfo("link title") = "Get ready for Lotusphere 2006!"
This little sets up a List for gathering the info. I use a list because it makes the prompting, storage, and usage of information much easier. I also add some example/default values to it to help the user know what is expected.
Print "Prompting for user info..."
Forall u In userinfo
u = Inputbox("Please enter your " & Listtag(u) & ":", Ucase(Listtag(u)), u)
End Forall
This next bit cycles through the list elements and prompts for the information. The list makes this much cleaner and smaller code.
Print "Detaching files..."
REM now update the file
REM detach it first
retflg = detachFile(thisdoc, "Body", "my_sig.htm", sigpath)
retflg = detachFile(thisdoc, "Body", "LotusBar.jpg", sigpicpath)
I then detach the files using my detachFile function, which is available in the LS utilities library I have available for download from this site. I have added it to the button code, since the library isn't available to me in the user's mail file.
Print "Loading sig file into code..."
REM load the sig file into a var
Set sigstream = s.CreateStream
If Not sigstream.Open(sigpath) Then Error 1000, "Unable to open file stream: " & sigpath
sigstream.Position = 0
sigcode = sigstream.ReadText
Call sigstream.Close
I have become a real fan of using the NotesStream class to work with text files. It is much easier than doing it the old File, Freenum, etc. way. This simply loads the file into a stream, then places the text of the stream into a variable called sigcode.
Print "Updating sig code..."
REM update the code with the info
Forall i In userinfo
sigcode = Replace(sigcode, "%%" & Listtag(i) & "%%", i)
End Forall
I then use Replace to find my holder tags in the HTML file and replace it with the user's information. Once again the List makes it much cleaner and simpler to do. My holder tags are in the format of %%tag%%.
Print "Writing sig file back to the file (" & sigpath & ")..."
REM write the updated code back to the file
Set sigstream = s.CreateStream
If Not sigstream.Open(sigpath, "ASCII") Then Error 1000, "Unable to open file stream: " & sigpath
Call sigstream.Truncate ' empties the file if there is stuff in it
Call sigstream.WriteText(sigcode, EOL_CRLF)
Call sigstream.Close
Delete sigstream ' to make sure the handle is released
I then use the NotesStream class to write the code back into the file. The Truncate method clears out the file, so I don't just append the text to the end.
Print "Sig file creation complete - enabling sig file for mail..."
Print "Getting handle to Mail Preferences..."
Set mailprof = thisdb.GetProfileDocument("CalendarProfile")
Call mailprof.ReplaceItemValue("EnableSignature", "1")
Call mailprof.ReplaceItemValue("SignatureOption", "2")
Call mailprof.ReplaceItemValue("Signature_2", sigpath)
Call mailprof.ComputeWithForm(True, False)
Call mailprof.Save(True, False)
This simply updates the mail file preferences profile. I spelunked the database to determine the item names. I also found that I needed to call a ComputeWithForm to make it all work.
Conclusion
That's it! This has been tested, and works really well - the nongeeks appreciate being able to create a nice sig file without needing to know how to code, or even how to enable it in their mail file. This could be enhanced to either use the existing graphic file, or prompt the user for a new one, but I didn't need that for this purpose.
Enjoy!
Rock
**Do not meddle in the affairs of dragons, 'cuz, like, you are crunchy and taste good with ketchup.









Blog Roll










Comments
I posted about it here.
Enjoy!
Rock
Posted by Rock At 02:21:27 PM On 08/12/2005 | - Website - |
Can't wait to see it - I will post it as a followup, with full credit to you of course
Rock
Posted by Rock At 10:56:51 AM On 08/12/2005 | - Website - |
I had thought of placing it in a neutral location, but I'd need to add some stuff in there to check for the directory (using Dir) and create it if it doesn't exist (MkDir). I'd also need to set the image path in the HTML file as well. Easy to do, but I thought I'd keep it simple.
BTW, anyone else reading this - does anyone know if there is an environment variable that delivers the exact path to the My Documents directory? I guess some users can rename that directory, and it would be good to be able to get that info.
Sounds great, Doug - we can catch up at Lotusphere!
Rock
Posted by Rock At 09:48:52 AM On 08/12/2005 | - Website - |
How are things in SUNY-land?
Keep in touch!
Rock
Posted by Rock At 10:57:39 PM On 08/11/2005 | - Website - |
Posted by Doug Cohen At 10:11:42 PM On 08/11/2005 | - Website - |
FYI .. the image isn't showing up for me.
TTYL. N.
Posted by neil agate At 04:30:52 PM On 08/11/2005 | - Website - |
Rock
Posted by Rock At 05:07:36 PM On 08/11/2005 | - Website - |
Everyone seems to want the new signature option. My only concern is that the 'Cancel' option isn't really an option. Once in the code it runs through whether you want to cancel out or not.
Kay
PS. Got the tip to come here from the SearchDomino.com site
Posted by Kay At 10:50:33 AM On 08/30/2005 | - Website - |
"i completely rewrote that script lib, it shouldn't even be in the database any more."
"well why don't you just put it in the toolet?"
Posted by jonvon At 09:53:07 AM On 08/12/2005 | - Website - |
Check out our website. We are in the process of overhauling it and this signature will help reinforce the new look by allowing us to add the new logo. I'll pass along my mods when I get them done. The only one I have right now is the issue of the directory that you are using. I use 3 different pc's and happen to have different directorys for my "My Documents" folder. For example, on my desktop at the office, my login name is different than on my laptop. All in all, the script will work, I'm just thinking of having our org use a folder directly on the c drive. Most will not even know it is there, but it will work better cross computer.
Posted by Doug Cohen At 08:30:40 AM On 08/12/2005 | - Website - |
Posted by Del At 09:35:19 AM On 09/26/2005 | - Website - |
Great idea - I'll see if I can convince our users to use a uniform signature if it's that easy to create one for them.
Have you tried
Evaluate(@RegQueryValue("HKEY_CURRENT_USER"; "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"; "Personal"))
to get the path to the My Documents directory?
Posted by Jens Polster At 12:05:52 PM On 08/12/2005 | - Website - |
Posted by Meshal At 12:32:00 AM On 08/31/2005 | - Website - |
"It has to be mailable - so all of the files and code has to be able to be contained in a single mail memo"
Also, if you follow the update link, I make it clearer.
Geesh, do I have to do everything for you?
Seriously, I should have made it clearer. And thanks, I am glad you approve
Rock
Posted by Rock At 03:12:57 PM On 08/16/2005 | - Website - |
For example:
Work desktop: c:\documents and settings\cohendo\...
Laptop: c:\documents and settings\dcohen\...
When you look at your Calendar Profile (Tools--Preferences--Signature tab), the path to the HTML file is in that field. When the directory does not exist, you are prompted with a "file does not exist error" and no signature appears. This meant that I would need to update my Signature settings in my mail database each time I went to a computer with a different My Documents directory.
Your statement of how you need to use a neutral directory is what I was changing it to. Since this is really only a 2 file deal (1 image and 1 html file), I just set both files to be in the same directory.
My updated code is on its way to you as soon as I finish typing this.
Posted by Doug Cohen At 10:04:35 AM On 08/12/2005 | - Website - |
I fiddled, and faddled and made it work. Very kewl sir.
Posted by Newbs At 02:18:10 PM On 08/16/2005 | - Website - |