Incoming Email settings link disappears from document library settings
One of my customer had created a custom document library deriving from OOTB document library. They are able to create their document library from custom list definition properly without any issues. But when in the document library created using custom list definition, if you go to list settings page, it does not show "Incoming Email settings" link under "Communications" column. Incoming Email settings are setup properly and OOTB document library has got incoming email settings link and it is getting emails properly. Just libraries created from their custom list definition does not have Incoming Email settings link!
So what is causing the issue?
Digging into SharePoint, found that this is hard-coded and SharePoint will only show Incoming Email settings link for OOTB lists of type Announcements, Event, Document Library, Picture Library, XML Form, Discussion Board, Posts.
Then what is the solution?
If you create a custom list, you need to create a custom email event handler and attach to your list and then Incoming Email settings link will be available. But that would also mean you miss out on the default settings like security, save original email etc. which are provided by OOTB incoming email settings page. With custom list, you are able to set just that whether list is allowed to received email and if yes, what is the alias.
If you are creating your own email event handler and attaching to a list, you would need to handle everything else yourself like email attachments, save the original email, security etc. which is by-default handled by SharePoint otherwise.
Here is a sample code for an Email event handler which you can use as a building block:
1: using System;
2: using System.Collections.Generic;
3: using System.Text;
4: using System.IO;
5: using Microsoft.SharePoint;
6: using Microsoft.SharePoint.Utilities;
8: namespace SimpleEmailHandler
10: public class EmailHandler : SPEmailEventReceiver
12: public override void EmailReceived(SPList list, Microsoft.SharePoint.Utilities.SPEmailMessage emailMessage, string receiverData)
14: base.EmailReceived(list, emailMessage, receiverData);
16: // Add the whole email to the document library as .eml file
17: SPFile mFile = list.RootFolder.Files.Add(DateTime.Now.ToLongDateString() + "--" + DateTime.Now.ToLongTimeString().Replace(":", "-") + ".eml", emailMessage.GetMessageStream());
19: // Get the SPListItem from the file just added
20: SPListItem item = mFile.Item;
22: // Update the title, from and subject fields
23: // Make sure your list have got From and Subject fields in it
24: item["Title"] = "Recvd:" + DateTime.Now.ToString();
25: item["From"] = emailMessage.Headers["From"];
26: item["Subject"] = emailMessage.Headers["Subject"];
28: // Update the item so that change made above are saved
31: // Now we will add the attachments in the email to the document library
32: foreach (SPEmailAttachment attachment in emailMessage.Attachments)
34: byte attachmentArray = new byte[attachment.ContentStream.Length];
35: attachment.ContentStream.Read(attachmentArray, 0, (int)attachment.ContentStream.Length);
36: list.RootFolder.Files.Add(DateTime.Now.ToLongTimeString().Replace(":", "-").Replace("/", "-") + "--" + attachment.FileName, attachmentArray);
39: // Send an EventLog entry saying that we are done with the email processing...
40: System.Diagnostics.EventLog.WriteEntry("SimpleEmailEventHandler", "Simple Email event handler called...");
As always… Happy Coding