Programmatically figure out the Email address of a list

I like mail enabled lists – they’re not perfect, but they are nice, and most folks can handle working email.

Sometimes, though, you want to programmatically create and enable these lists. That’s cool – but how do you figure out the email address of the list afterward?

You can get the first part of the address from the SPList object’s EmailAlias property. But that’s only the bit before the ‘@’ sign – what about the end of the address? Well, you get that from the farm:

emailAlias = list.EmailAlias + "@" + SPFarm.Local.Services.GetValue<SPIncomingEmailService>("").ServerDisplayAddress;

This gets the rest of the address (in my case ‘sharepoint.virtual.local’). Job done.

Advertisements
Programmatically figure out the Email address of a list

One thought on “Programmatically figure out the Email address of a list

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s