Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

All you need to do is set the EmailAlias to the list. You should also check out http://www.novolocus.com/2009/04/15/programmatically-create-and-configure-mail-enabled-lists/ for advanced properties to set.

share|improve this answer
    
sorry it's been a while ago that i've done this. Normally EmailAlias is all you need to set. There are some more advanced properties that could be set to so check out the second article i posted now. –  Stefan Bauer Oct 31 '11 at 20:00
    
Thanks that looks like it did the trick –  AndrewSwerlick Oct 31 '11 at 20:10
    
I take it back I'm still running into issues. The email is never showing up in the library. I had this working with a manually generated library, so I'm pretty certain my general settings are right. Also, I can see the email hitting the SMTP drop folder and then disappearing after a few minutes. Interestingly the code generated document library does not have the same options as a manually generated one.I added the code I used to generate the list as an edit. –  AndrewSwerlick Oct 31 '11 at 20:39
    
I figured out the issue, per this link blogs.msdn.com/b/malag/archive/2009/05/13/…. I had created and attached my own event reciever in my code, not realizing this event reciever would fire before emails were added to the list. I thought it would fire after sharepoint had already added things to the list. Also SharePoint hides all the options when you have your own reciever attached –  AndrewSwerlick Nov 2 '11 at 19:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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