Mavention Blog > Februari 2009

Programmatically enable and configure the email address on a SharePoint library

Hi All,

Have you ever wanted to programmatically enable receiving of mail on a SharePoint list or library?

Here's how you can accomplish this.
Suppose your domainname is : mydomain.local


// Get the list
using (SPSite site = new SPSite(@"http://portal.mydomain.local"))
{
    using (SPWeb web = site.RootWeb)
    {
        SPList list = web.Lists["Documents"];
 
        // Check if this list is able to receive email. Not all list types are able to receive email.
        // Only the following list types are able to receive email:
        //  - Document, picture, or form library
        //  - Announcements list
        //  - Calendar list
        //  - Discussion board
        //  - Blog
        //
        if (list.CanReceiveEmail)
        {
            // Set 'Allow this document library to receive e-mail?' to YES.
            list.EnableAssignToEmail = true;
 
            // Set 'E-mail address:' to the following address
            list.EmailAlias = "manuals";
 
            // Don't forget to save the changes you've made
            list.Update();
        }
 
    }
}


After you've run this code you now can send emails to
manuals@mydomain.com

ps. Make sure that you've setup the outgoing/incoming mailsettings in Central Admin -> Operations before running this code!


That's all folks!!!

Ciao,
Niels
 
Posted: 20-2-2009 23:09:07 by Niels Loup | with 0 comments


Commentaren
Blogbericht heeft op dit moment nog geen commentaren.
Laat commentaar achter



 Security code