Is there a way to enable and configure incoming email for a document library using the C# api for sharepoint 2010

sharepoint.stackexchange https://sharepoint.stackexchange.com//questions/22396

  •  06-12-2019
  •  | 
  •  

Pregunta

I've got a requirement to allow users to approve or disapprove certain actions by replying to auto generated emails. I've already got a good handle on how to use email enabled lists and event receivers to do this, but what I can't figure out is how to spin up an email enabled list in a feature receiver. I'd rather not have any manual deployment steps for this solution. Is there a good way to enable incoming email for a document library via code?

EDIT: Tried the proposed solution below but still run into some issues. It compiled but the email never showed up in the library. Here's the code I used to generate the list

public override BaseListGenerator GenerateList(Microsoft.SharePoint.SPWeb web)
        {
            _list = web.Lists.TryGetList(title);
            if (_list == null)
            {
                var listId = web.Lists.Add(title, "", SPListTemplateType.DocumentLibrary);
                _list = web.Lists[listId];
            }

           _list.EmailAlias = "isourcingapprovals";


            int numRecieversRegistered = _list.EventReceivers.Cast<SPEventReceiverDefinition>().Where(d => d.Class == typeof(ApprovalEmailEventReciever).FullName).Count();

            if (numRecieversRegistered == 0)
                _list.EventReceivers.Add(SPEventReceiverType.EmailReceived, Assembly.GetExecutingAssembly().FullName, typeof(ApprovalEmailEventReciever).FullName);

            _list.Update();
            return this;
        }
    }

UPDATE: I resolved this issue too. See the comment on the accepted answer

¿Fue útil?

Solución

All you need to do is set the EmailAlias to the list.

Licenciado bajo: CC-BY-SA con atribución
scroll top