Wednesday, December 5, 2007

Using SPEmailReceiver event handler (MOSS)

I had a requirement that i wanted email be configured for a document library. On the arrival of the email, the email body was to be parsed and the subject of the mail, some important info from the body had to be updated into a list.I found some options which i could make use of, like

1. SPEmailReceiver - I had major problems with this. Some of them were,
a. As soon as i activated this feature(i installed this event handler as a feature(obvious)), the email which was obediently coming into the document library, stopped coming. I worked on it for a significant amount of time but to no avail.
b. The event handler never fired. I tried many times. I searched for a solution for a very long time but to no avail. Then i decided to move on. The solution was workflow.
2. Write a workflow which activates on Item Update. Configure the document library to receive email and check the box which says, save content. In the workflow, write the required logic to parse the data. - I found some glitches here. The email was always stored as .eml file. I did not know how to parse a .eml file.
3. When i was pondering as to how i could parse a .eml file,my team came up with a suggestion that i could use Timer service instead of a workflow and parse the .eml file(workflow would anyway be a poor choice as it was a single course of action). I tried using this and it worked perfectly.(by this time, i knew how to parse .eml file)

As you can see with the 3 choices, the first choice was the most natural one. But i was forced to use the third choice. But i really wanted to use the SPEmailReceiver event handler. I finally came up with the solution. The problem was not with the event handler(I had done that properly). But it was the process i was associating with.
While debugging, this event handler must be attached to not only the w3wp processes but also the owstimer service process. There were cacheing problems with this owstimer service too. So if you do face problem in executing the code, just kill the owstimer process, deactivate feature, uninstall feature, install feature, activate feature and do an IISRESET. This should do the trick.This will get the debug working and the flow will go into event handler. If the code present there is proper, it'll work with out any glitches. If you have a better method, do reply.
Cheerio

No comments: