Friday, June 15, 2007

Add value to your email - Updated

The following code is evolution of what I wrote in 2004. The only change in the folliwing code is it will replace the word AEtip with the content, everything else including the content storage is just the same.

Code Copy HideScrollFull



Option Explicit



Private Sub Application_ItemSend(ByVal Item As Object, Cancel As
Boolean)

'Author : Amith Ellur'Date : 20 May 2003

'Idea Conceived : Dr. Nitin Paranjape

On Error GoTo Hell

'holds the reference to ValueAdd subfolder in my personal folders

Dim mValueAddFolder As MAPIFolder

'holds the reference to a randomly selected folder with in "Of the day"

Dim mRandomFolder As MAPIFolder

'holds the reference to a randomly selected message from the randomly
selected folder

Dim mRandomMessage As PostItem

'the case sensitive folder structure expected is "Personal Folder->ValueAdd->Of
the day".

'With in the "Of the day" folder you can create multiple folder to
categorize the content

'I have Definition,Info, Murphy's Computer Law, Thought, Tip

'So the header of the content becomes randomly selected folder name
concatenated with " of the day" example "Murphy's Computer Law of the
day"

Set mValueAddFolder =
Application.Session.Folders("Current").Folders("ValueAdd").Folders("of
the day")

'this is the escape sequence for Subject EOM messages

'if the body contains "<AETip Of The Day>" i replace it with content

If InStr(Item.Body, "<AETip>") <> 0 Then

'Mail format has to be HTML please set this on Tools->Options->Mail
Format->Compose in this message format.

'this check ensures i don't add the content while i reply the mail for
the second time

If InStr(Item.HTMLBody, "of the day") = 0 Then

'processing needs to be done only if i have any subfolders in my "Of the
day" folder

If mValueAddFolder.Folders.Count >= 1 Then

Set mRandomFolder =
mValueAddFolder.Folders(Int((mValueAddFolder.Folders.Count * Rnd) + 1))

If mRandomFolder.Items.Count >= 1 Then

Set mRandomMessage = mRandomFolder.Items(Int((mRandomFolder.Items.Count
* Rnd) + 1))

'just adding some format so that the content has a header and sending
using HTML format

If Trim(mRandomMessage.HTMLBody) = "" Then

'Item.HTMLBody = Item.HTMLBody + "<P><B><FONT SIZE=2 FACE=Verdana>" +
mRandomFolder.Name + " of the day...</FONT></B></P>" +
mRandomMessage.Body

Item.HTMLBody = Replace(Item.HTMLBody, "&lt;AETip&gt;",
mRandomFolder.Name + " of the day: " + mRandomMessage.Body)



Else

'Item.HTMLBody = Item.HTMLBody + "<P><B><FONT SIZE=2 FACE=Verdana>" +
mRandomFolder.Name + " of the day...</FONT></B></P>" +
mRandomMessage.HTMLBody

Item.HTMLBody = Replace(Item.HTMLBody, "&lt;AETip&gt;",
mRandomFolder.Name + " of the day: " + mRandomMessage.Body)

End If

End If

End If

End If

Else

End If

Hell:

End Sub
. . .

1 comment:

Milind said...

Hi Amith,

Sorry for asking a real dumb question, but how would I make sure that after copying this code to my outlook (as a VBA project with .OTM extension)it will actually execute everytime I compose a new mail and the tip of the day actually appears in my signature ?