Question

I have a document library setup to recieve emails. The emails coming in have a single picture and a csv file which I use for some processing.

The override emailrecieved works perfectly but of course as I override I lose the nice SharePoint functionaliy that saves the incomming email as configured in the settings.

It was my understanding that I could call MyBase.EmailRecieved in my event for the underlying functionality to still work. This however is not working and no record of the email coming in is getting retained.

For now I am explicitly creating an audit trail but I would like to rely on SharePoints existing functionality as I believe it will be more robust.

What am I doing wrong with the MyBase.EmailRecieved call? Or what can I do instead if this doesnt work?

Thanks in advance.

Était-ce utile?

La solution

When writing your own EmailReceived event receiver you will loose the default functionality.

What you will have to do is to implement this default functionality yourself. Let me give you a simple example. The following example saves all mail attachments to the list if they are *.csv files. You can do the same with the emailMessage and save it to the list as well. As you can see it is as easy as to add Files.Add to add a file to a document library.

public override void EmailReceived(SPList list, SPEmailMessage emailMessage, string receiverData)
{
    SPFolder folder = list.RootFolder;

    //save attachments to list
    foreach (SPEmailAttachment attachment in emailMessage.Attachments)
    {
        if (attachment.FileName.EndsWith(".csv"))
        {
            var attachmentFileName = attachment.FileName;
            folder.Files.Add(folder.Url + "/" + attachmentFileName, attachment.ContentStream, true);
        }
    }

    list.Update();
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top