« Feeling divine inspiration lately? Become a GOD | Main| Our own Bob Balaban in Spencer Katt!! »

Kewl Code: Automated Signature Block Wizard

QuickImage   
Category
Bookmark : del.icio.us  Technorati  Digg This  Add To Furl  Add To YahooMyWeb  Add To Reddit  Add To NewsVine 


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.

Comments

1 - I have updated the toolet with Doug's code (THANKS DOUG!) and have also added code that allows the user to change the graphic if desired.

I posted about it here.

Enjoy!

Rock

2 - Ahh, makes sense. Replication, what a concept

Can't wait to see it - I will post it as a followup, with full credit to you of course

Rock

3 - Doug - it determines the My Documents directory based on the user's current login profile for the computer running the button. So, when I click the button it places it in C:\Documents and Settings\Rock\My Documents and C:\Documents and Settings\Rock\My Documents\My Pictures. When I mail that same email to another person, say "Doug" (and his Windows login is "Doug") then it will place it in C:\Documents and Settings\Doug\My Documents and C:\Documents and Settings\My Documents\Doug\My Documents\My Pictures.

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

4 - Doug - Glad you like it Is this something you can use in your org? I'd be curious to hear how you use it, modifications you make, etc.

How are things in SUNY-land?

Keep in touch!

Rock

5 - Rock, this is great. Thank you.

6 - Rock,

FYI .. the image isn't showing up for me.

TTYL. N.

7 - Fixed, Neil - thanks for the heads-up!

Rock

8 - Excellent. Looks really good and is a big hit for us.

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

9 - toolet - lol, sounds like a great place to put, er, maybe code you don't want anymore?

"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?"

10 - Rock: Things in SUNY land are hectic. We are looking at some serious technology decisions in the near future, all of which will be exciting for the geek squad!

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.

11 - Rock, running into a problem with creating this awesome buttom. When I try to create the button, Run is grayed out. Can I get around this? Am I missing some magical access?

12 - @6 - Rock
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?

13 - heading CSS

14 - @Newbs (12) - Silly boy, I mentioned it in the bullet in the post, first one:

"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

15 - Rock.. yes, I saw that the button determined the My Documents directory based on the user's Windows login, but there is an issue with that. I use the same server replica of my mailbox across machines where the My Documents folder is in different locations.

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.


16 - Perhaps I missed the part in the instructions that said this was intended to be a button in a Notes Mail message. And that the files had to be attached before the button would work,,,

I fiddled, and faddled and made it work. Very kewl sir.

Meet Rocky

Rock - February 2010
Rocky Oliver
If you see me at a conference, please stop me and say hi!

Calendar

Search

Categories

Proudly Employed By

Wofkflow Studios

Thawte Notary

Thawte Web of Trust Notary

LOTUS GEEK gear

Social Networking


Add to Technorati Favorites

View Rocky Oliver's profile on LinkedIn

Rocky  Oliver

LotusGeek Blog Roll

Why display a blog roll when Planet Lotus does it so much better?

Dilbert

Buy my book!

Blog Buttons

Atheist - Unitarian - Humanist

Poker Players Alliance