I have a Document Library with an email associated with the OOTB feature. When I send to the library an email with some attachments, every attachment is stored with one of the OOTB methods (divided in folder by sender).

I need to do some operation whenever a new file is added so I tryed to add an event handler. I tried every method but:

  • When I upload a file from the SharePoint UI the event handler is triggered
  • When I upload a file by e-mail it is not

Is there any way to do that?

Thank you very much!

1 Answer 1


There are custom events for incoming emails, have you looked for "Email events"? If you add such Event Receiver you might have to handle the item correctly as well, or else it will not be inserted properly.
Like this:

public class OnEmail : SPEmailEventReceiver

   public override void EmailReceived(SPList list, SPEmailMessage emailMessage, String receiverData)
       base.EmailReceived(list, emailMessage, receiverData);

       var item = list.AddItem();
       item["Title"] = emailMessage.Headers["Subject"];
       item["EmailSubject"] = emailMessage.Headers["Subject"];
       item["EmailFrom"] = emailMessage.Headers["From"];
       item["EmailHeaders"] = emailMessage.Headers;
       item["EmailSender"] = emailMessage.Headers["x-sender"];
       item["EmailTo"] = emailMessage.Headers["To"];
       item["Body"] = emailMessage.HtmlBody;
       emailMessage.Attachments.Cast<SPEmailAttachment>().ToList().ForEach(attachment =>
           var array = new byte[attachment.ContentStream.Length];
           attachment.ContentStream.Read(array, 0, (int)attachment.ContentStream.Length);
           item.Attachments.Add(attachment.FileName, array);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.