You’ve Got Mail (And an Image) !!

March 30, 2007 at 3:25 pm (Embedded Image, Lotus Notes, PassThru HTML)

My clients threw an unusual request at me; somebody higher up in the hierarchy wanted a way to track the number of people who were even opening a particular newsletter email.

Ok, well, simple – could easily do with plain ole’ read receipts, or so I thought. Apparently, not – the whole thing had to be done in a way completely transparent to the user-base. So read-receipts were definitely out (especially since disabling read-receipts is not exactly rocket-science!). My next suggestion was to have some code in the mail’s PostOpen on QueryClose event, to increment the count in another database. But it turned out that the client had something much more tricky in mind. He wanted to insert an image-reference URL inside the email, which would automatically be loaded up from the source (much like an image inside a website is loaded). The number of ‘hits’ to the image could then be computed.

Hmm… tricky. First, I thought of inserting an image resource into the email, and then use the owner database of the image resource to compute the number of hits. This seemed feasible especially since you can now insert image-resources from other databases too. Unfortunately, the image seems to be embedded into the email, and is not treated as a reference to the database. I sent out an email with such an image inside to multiple people, who did open their emails but were not recorded by the database. So that came to nought.

My next thought was to use passthru-HTML to notate an image reference using an <img> tag. I opened up my Memo form in designer, did the Store-Form-in-Doc and Render-passthru-HTML checks. Then I proceeded to create a new Memo, inserted an <img> reference, turned on passthru for the tag and then sent it out. However, that didn’t work either; though a form with a passthru <img> tag on it works fine.

After a lot of digging, I found out that mere passthru HTML on a memo probably wouldn’t cut it – because, Lotus Notes’ native data format is something called Composite Data (CD). Thus passthru-HTML doesn’t ultimately behave like ‘real’ HTML, instead it gets converted to this CD format. And because its in the CD format, the HTML doesn’t get rendered. So what would be a good way to force a mail to render HTML on its pages? MIME, of course. I mean, emails that come into a LN mailbox from internet-addresses like gmail and yahoo render images correctly, so MIME has to work.

With that idea in mind, I played around with the Notes MIME classes, and finally got it to work. The script I used (rather frayed around the edges, needs more fine-tuning) was this:

‘———- Creating a MIME Email —————-
Dim session As New NotesSession
Dim ws As New NotesUIWorkspace
Dim db As NotesDatabase
Dim maildoc As NotesDocument
Dim mime As NotesMimeEntity
Dim mimeHeader As NotesMimeHeader
Dim mimeChild As NotesMimeEntity
Dim stream As NotesStream
Dim recipients As Variant

recipients = ws.PickListStrings(PICKLIST_NAMES, True)
If Isempty(recipients) Then
Msgbox “Cannot proceed without specifying who this mail has to be sent to”
Exit Sub
End If

Set db = session.CurrentDatabase
Set maildoc = New NotesDocument(db)
maildoc.Form = “Memo”
maildoc.Subject = “Checking out image references”
maildoc.SendTo = recipients

Set stream = session.CreateStream
session.ConvertMime = False
Set mime = maildoc.CreateMimeEntity
Set mimeHeader = mime.CreateHeader(“Content-Type”)
Call mimeHeader.SetHeaderVal(“multipart/mixed”)

‘—Create Message Text ———–
Set mimeChild = mime.CreateChildEntity
Call stream.WriteText(“The purpose of this email is to test whether image references work corectly” & Chr$(10) & Chr$(10))
Call stream.WriteText(“<img src=’http://riscapp03.metlife.com/auddbs/starsforum.nsf/Help.jpeg’ alt=’Publications DB’>”)
Call mimeChild.SetContentFromText(stream,”text/html”,ENC_NONE)
Call stream.Close

Call maildoc.Send(False)

With a bit of fine-tuning (probably to accept the URL of the image as well), the script would be ready for delivering to the client. Gotta admit, this support for MIME is cool. Have never played around with it much, so it opens up some interesting possibilities.

Post a Comment