Overriding SPEmailReceiver for Email Enabled libraries

Tech-Archive recommends: Speed Up your PC by fixing your registry



Hi All,

Has anyone ever had any luck overriding the SPEmailReceiver class for
a document library? I have coded a simple one, but am having problems
getting it to fire.

----
namespace
Eversheds.SharePoint.Portal.EventHandlers.KnowledgeSubmissions
{
public class EmailHandler : SPEmailEventReceiver
{
public override void EmailReceived(SPList list,
Microsoft.SharePoint.Utilities.SPEmailMessage emailMessage, string
receiverData)
{
base.EmailReceived(list, emailMessage, receiverData);

SPListItem listItem = list.Items.Add();
listItem["Title"] = emailMessage.Headers["Subject"];
listItem["Body"] = emailMessage.HtmlBody;

foreach (SPEmailHeader hdr in emailMessage.Headers)
{
string name = hdr.Name;
string value = hdr.Value;
}

}
}
}
----

I have tried binding it to my list with a <Receivers> element in my
feature's elements.xml:

----
<!-- Email Event Receiver for the Knowledge Submissions Library -->
<Receivers ListTemplateOwner="EE2458B8-4594-4bef-A9F9-29D9F3D3A632"
ListTemplateId="101">
<Receiver>
<Name>EmailHandler</Name>
<Type>EmailReceived</Type>
<SequenceNumber>10000</SequenceNumber>
<Assembly>Eversheds.SharePoint.Portal.EventHandlers,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f525b76b9e4fb66</
Assembly>

<Class>Eversheds.SharePoint.Portal.EventHandlers.KnowledgeSubmissions.EmailHandler</
Class>
</Receiver>
</Receivers>
----

and also in code within my feature event receiver with a SPList.call:

----
//Set the item rec'd event handler against Knowledge Items library
string assm = "Eversheds.SharePoint.Portal.EventHandlers,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f525b76b9e4fb66";

string nsp =
"Eversheds.SharePoint.Portal.EventHandlers.KnowledgeSubmissions.ItemHandler";
web.Lists["Knowledge
Items"].EventReceivers.Add(SPEventReceiverType.EmailReceived, assm,
nsp);

//Set the email rec'd event handler against Knowledge Items library
nsp =
"Eversheds.SharePoint.Portal.EventHandlers.KnowledgeSubmissions.EmailHandler";
web.Lists["Knowledge
Items"].EventReceivers.Add(SPEventReceiverType.EmailReceived, assm,
nsp);
----


but everytime I expect it to fire, I get the follow app event log
error:

----
Event Type: Error
Event Source: Windows SharePoint Services 3
Event Category: General
Event ID: 6644
Date: 25/07/2008
Time: 10:15:02
User: N/A
Computer: EVERSHEDS
Description:
Event manager error: Could not load type
'Eversheds.SharePoint.Portal.EventHandlers.KnowledgeSubmissions.EmailHandler'
from assembly 'Eversheds.SharePoint.Portal.EventHandlers,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f525b76b9e4fb66'.

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.
----


I am fairly certain my type information is correct (have checked it
via Reflector), but just to make certain, I changed the code in my
"ItemHandler" event handler (which has been working fine) so that its
namespace had the email receiver in it - and got the same type error!

This is driving me crazy - I expected the ItemReceiver to fire when
emails were delivered to the library, but this doesn't happen (why
not?!?), so I thought I would be able to use this event handler to
handle the stuff I want to do to email - but no luck!

If anyone can see where I am going wrong, or could provide some code
snippets for a handler that actually works (binding and handler
please) I would really appreciate it.

Cheers,

Nigel
.



Relevant Pages

  • Re: cannot retrieve dropdownlist selected value
    ... It looks to me that the extractedCSS dropdown only gets populated when the event handler addTagButton_Click is executed. ... SaveTagButton_Click event handler executes. ... string subdomain = f.GetSubdomainNameById; ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: cannot retrieve dropdownlist selected value
    ... Just validate that there are items in the extractedCSS dropdown when the SaveTagButton_Click event handler executes. ... string subdomain = f.GetSubdomainNameById; ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: String between unmanaged and managed
    ... Directly from Help on PostMessage: ... exit before the receiver copies off the data (it's quite likely to happen in ... PostMessage(hwndinoc, 20000, (WPARAM) textitem, textlen); ... I have tried, the problem is that I always receive an invalid string, ...
    (microsoft.public.windowsce.app.development)
  • Re: question for the experts
    ... > I send output to the port "Send message To" ... > it will then reply with "Joe Smith" as a valid receiver.. ... >>>> meets your criteria (e.g. matching a string). ... >>>>> RxMESSAGE for data comming in as so. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: question for the experts
    ... You should do nothing but put it into an app buffer and ... > private void button1_Click ... I want to enter in the receiver id.(this may take a ... do your checking/parsing in the event handler of the DataReceived ...
    (microsoft.public.dotnet.framework.compactframework)