Saturday, May 29, 2010

Installing and configuring SMTP and POP3 e-mail for sharepoint 2010

Introduction

After having installed a development environment we can complete our installation by installing and configuring SMTP and POP 3 service on our Virtual machine.

Developer benefits (the "Why" part of the post)

It would be interesting to have a way to send and receive e-mails inside our development environement in order to:

  1. Configure and test incoming e-mail for SharePoint 2010
  2. Configure and test outgoing e-mail for SharePoint 2010
  3. Configure and test SharePoint 2010 alerts
  4. Configure and test SharePoint 2010 contribution with e-mail sending

This installation steps

To be able to test all these SharePoint 2010 functionalities, we are going to:

  1. install the windows mail application
  2. install the SMTP server feature
  3. configure the SMTP server
  4. install a third party free POP 3 service
  5. configure our POP 3 service
  6. configure the windows mail application
  7. test e-mail sending and receiving within a Windows 2008 server R2 development environemnt for SharePoint 2010

1 - Installing the windows mail application

Download the Windows Mail software, the successor of outlook express for Windows 7 and Windows server 2008.

Start the installation.

 

2 - Installing and the SMTP server feature

On your Windows 2008 server R2 development machine start the Server Manager:

Click the Add Features link

Check the SMTP Server feature check box

The Web Server IIS Feature Wizard is opening since as you will see later, the SMTP Server configuration has to be done within the old IIS 6.0 console.

On Select Role Services Windows, let the default option (while I was tempted to check WebDav to be able to navigate through my SharePoint 2010 folders using Front Page RPC and WebDav protocols after having added a network place for a SharePoint site. But I had the pleasant surprise to discover it was already working, and I think it is thanks to Visual Studio 2010 installation...)

Validate the page of Confirm Installation Selection

This is the screen you should have after the installation of your SMTP Server Feature on your Windows 2008 Server R2 environment

 

3 - Configuring the SMTP server

As said before, the SMTP Server is configured using the old IIS 6.0 Microsoft Management Console, so open it:

We are now going to create a domain alias for our machine.

Assume we call it contoso.com

That is the screen after having created the alias

Now, open the SMPT Server properties

On the Access tab click Relay
The Relay Restrictions dialog is opening
Click Add
Enter the local IP of your machine.
Confirm all this and close dialogs.

If you reopen the Relay Restrictions dialog you should obtain this:

 

4 - Installing a third party free POP 3 service

As posted by Chris Stinson, while SMTP is alive and well in the Features section of the Windows 2008 Server Manager, POP3 has been removed from Windows 2008 altogether. Fortunately, Chris has also given a reference to a third party free solution:

Visendo SMTP (pop3) Extender for Windows 2008 Server

You will find the link to the 64 bits version, download it and start the installation

 

5 - Configuring our POP 3 service

To enable the Visendo SMTP (pop3) Extender for Windows 2008 Server do the following.
Assume we are wanting to create a mailbox for an account the e-mail address of which is administrator@contoso.com...

Start creating a folder at this location:

C:\inetpub\mailroot\Drop\administrator_contoso_com

Then, locate the visendosmtpextender.config and open it. It is located at:

c:\Users\All Users\ppedv\visendosmtpextender

And cofigure it as following:

<VISENDO>
<
POP3>
<
Outbound UseOutboundPop3="true" StoreFolder="C:\inetpub\mailroot\drop" ServerPort="110" ServerIP="127.0.0.1"/>
</
POP3>
<
accounts>
<
mailbox datadir="\administrator_contoso_com" destination="administrator@contoso.com" password="Passw0rd"/>
</
accounts>
</VISENDO>

Finally, restart the Visendo SMTP Extender Service

6 - Configuring the windows mail application

Open Windows mail,

and if there is no account created yet, the software will ask you to create one.

Type the previous administrator e-mail account information in the first dialog

and the server information linked to this account in the second dialog

Close the last dialog that confirms the successful creation of the administrator email account

 

7 - Testing e-mail sending and receiving

Now, we just have to test if all is working properly.

As you should be signed in within Windows Mail as administrator@contoso.com, try to send an e-mail to this account.

Start several sync operations. Do not worry, it can take few minutes until...

the e-mail finally arrives...

Well done!
We can now use all e-mail functionalities offered by SharePoint 2010 in our Windows server 2008 R2 development environment.

 8 - Configuring incoming e-mail settings (SharePoint 2010 - local service accounts)

Now is the time to configure incoming e-mail settings for our environment ie a development machine using local accounts. So the configuration  will be very easy since we will not have to manage with settings linked to Active Directory.
So open the SharePoint 2010 Central Administration and click on System Settings.

Then, on the System settings page, on the configure incoming e-mail settings link

Here, quite let all default options, 

just enable sites on this server to receive e-mails
settings mode --> automatic
DO NOT use SharePoint Directory Management Service (there is no Active Directory available in our case anyway)
complete E_mail server display address with our alias --> contoso.com
Accept mail from all e-mail servers

 9 - Configuring outgoing e-mail settings (SharePoint 2010 - local service accounts)

Go back using your browser to return to the system settings page and this time click the "Configure outgoing e-mail settings link"

Here is the proper configuration for our environment:

 

10 - Giving an e-mail address to the local users accounts

Now, we want to test what we have configured, but to do it, we need user accounts with an available e-mail address . Unfortunately, as we are using local accounts, when we have registered them in the SharePoint content databases, there were no way at this time to automatically obtain an e-mail address from an Active Directory or an LDAP. To do this, while we could use the SharePoint 2010 UI by editing each account properties, I will rather take advantage of this operation to show how easy it is to program a fast sharePoint 2010 configuration task using the SharePoint object model. By the way, imagine you have to do this operation for 1000 local service accounts...

So open Visual Studio and create an aspx file in the layouts directory under the 14 hive. Assume we call it setEmailAddress.aspx

Here is the code of our SharePoint 2010 application page:

<%@ Page Language="C#" AutoEventWireup="true" Inherits="Microsoft.SharePoint.WebControls.LayoutsPageBase" DynamicMasterPageFile="~masterurl/default.master"  %>

<%@ Import Namespace="Microsoft.SharePoint" %>

 

<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">

 

</asp:Content>

 

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">

<script runat="server">

   

    SPWeb myWeb = null;

    string message = string.Empty;

    string userName = string.Empty;

    public void Page_Load(object sender, EventArgs e)

    {

        myWeb = SPContext.Current.Web;

       

        message += "Welcome to " + myWeb.Title;

        message += "<br/><br/>This page was created with the minimal page directives required for SharePoint 2010 application pages...";

    }

    </script>

  

    <%

        message += "<br/><br/>Giving the users an e-mail address...<br/>";

 

        myWeb.AllowUnsafeUpdates = true;

       

        foreach (SPUser anUser in myWeb.AllUsers)

       {                      

            userName=anUser.Name.ToLower();

           

            if(!userName.Contains("system") && !userName.Contains("service")){                       

           

                userName=userName.Remove(0,userName.IndexOf(@"\")+1);

                anUser.Email = userName + "@contoso.com";             

                anUser.Update();       

                message += "<br>" + anUser.Email + " was sucessfully attributed";         

            }           

       }

          

           lblMessage.Text = message;

    %>

 

      <asp:Label id="lblMessage" runat="server" />

    

</asp:Content>

 

<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">

Set Users e-mail address

</asp:Content>

 

<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" >

Set users e-mail address

</asp:Content>

 

 

This is the way of quickly configuring Sharepoint while programming against the SharePoint 2010 object model. A simple application page with two page directives, and here you are, you have the intellisense and can start driving your SharePoint 2010 environments by writting HTML and C#. You will notice by the way that this 2 page directives are also enough to obtain a SharePoint 2010 application page with all the required presentation elements. Let us call it the SharePoint 2010 minimal Application Page.

Now execute the page and you should obtain something like this:

We can now check that our users were actually provided with an e-mail adress:

11 - Testing Incoming e-mail settings for a SharePoint 2010 list with local accounts

Create a discussion list in a sharePoint 2010 site, assume we call it forum. As we have enabled incoming e-mail at the Farm level, a new configuration parameter appear in the list settings:

Now, if we provide the "forum" list with an incoming e-mail address, users will be able to contribute to the list by sending e-mail to this address, and the authentication will be based on their e-mail address.

And if a user send an e-mail to this SharePoint 2010 list address,

a new entry will appear within the list.

12 - Testing outgoing e-mail settings for a SharePoint 2010 list with local accounts

now assume we had configured an e-mail alert for our other account, the Administrator one, he should have received a message about the previous e-mailed contribution.

And it is done!

 

13 - Aknowledgements and useful links

Thanks to Glafkos Charalambous for his post about SMTP Configuration

Thanks to hannespreishuber for his POP3 for Windows Server 2008

Thanks to Chris Stinson for his post about POP3 Protocol Missing in Windows 2008 / IIS7

And if you want to test mail receiving with telnet here are two useful links:

How To Enable Telnet In Windows Server 2008

Send Email via Telnet

10 comments:

Unknown said...

Thanks for the excellent tutorial. If my ISP blocks port 25, will this solution work?

Marc Charmois said...

Hi,

thank you,

notice that this solution is for a development environment, and I have used Visendo SMTP (pop3) Extender for Windows 2008 Server only because the service is not provided anymore by Windows Server 2008.
It is just a way to emulate e-mail sending and receiving with SharePoint to be able to develop and test solutions that involves e-mails.
As all is running locally on a stand alone computer using the 127.0.0.1 IP you even does not need an Internet Access!

I am not sure it is a good idea to use this configuration for a production environement since the current recommandations of Microsoft is now involving Exchange.

Check the post of Chris Stinson about it:
[...
POP3 has been depreciated and will no longer be supplied as part of the Windows OS. Although POP3 was introduced with Windows Server 2003, Microsoft removed it after including it in just one generation of the OS. Organizations that use the email protocol will need to use an alternative such as Microsoft Exchange Server or Small Business Server (SBS).

POP3 isn’t a very “good” method to retrieving mail and I know very few organizations that still utilize it. IMAP and Exchange connectors are far more feature-rich and useful especially in today’s multiple-device world. I do run a POP3 mail server for World’s Cutest Animals because it is quick, has minimal resource usage and is perfect for a mail server that only has a few mailboxes.
...]

Hope this helps.

Marc

Og Ramos said...

Thanks for the Tutorial.

I still can't move on from the test email with Windows Live Mail. It gives me a Socket Error 10061. I think it has to do with the firewall configuration. Even though it was a fresh install. I will try again.

Any suggestions?

jasear said...

jamiros, i had the same issue.

It turned out that my smtp server had stopped.

I simply went to iis6 clicked on the smtp server and restarted it. That solved the problem.

Oscar said...

I am stuck on step 10 (Giving an email address to the local accounts). I created the aspx page in the following directory: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS

I am getting an error when I attempt to browse to the page (i.e., http://domain.com/_layouts/setEmailAddress.aspx)

I did an IISRESET. Still getting an exception.

In the SCRIPT block, on the page, I am not getting intellisense on the sharepoint namespaces/classes (i.e., SPWeb, SPContext, etc.)

Any help or tips are very much appreciated. Thanks...

HARSHA said...

Hi,
I have successfully configured pop3 and smtpserver.Also i gave email id to the discussion board but , the list is not showing any incomming mails .

Kindly help me.

Anonymous said...

Here is an update to this info that is sorely needed. If you follow steps 5 and 6 exactly as in the article, IT WILL NOT WORK. I spent 2 whole days tracking down the issues. For step 5, DO NOT do the manual editing as depicted; it is actually much simpler, at least with the latest version of Visendo (and probably will not even work if you do what is in the article). All you have to do after installing Visendo is go into its UI, click on "Accounts", click on the "New Account" button, and add the account you need, such as administrator@contoso.com, with its windows password. Click on "Apply", click on "Finish". That's it for step 5. For step 6, the latest version of Windows Live Mail looks different than the screenshots in the article, AND most critically, where you see them specifying 127.0.0.1 for both the incoming server and outgoing server, WILL NOT WORK. You must specify the actual IP address of your server. (If you DO put 127.0.0.1 for those two values, you will receive an error when trying to do Send/Receive within Windows Live Mail client.) AND one other detail, where the article screenshot shows "login id", in latest Windows Live Mail dialog it says "Email username:" and that MUST be in the form of administrator@contoso.com, NOT just administrator (if you just put administrator, you will also get an error when trying to send/receive mail).

Also, the FULL standalone installer of Windows Live (including the Mail component, which is the only component you probably want to install) is a little hard to find, but as of 9/1/2012 can be found at: http://g.live.com/1rewlive4-all/en/wlsetup-all.exe, as discussed at: http://www.sevenforums.com/browsers-mail/128798-offline-install-windows-live-mail-2011-15-4-3508-a.html.

Also, one final thing, after installing the SMTP server feature and Visendo, make sure you go into Administrative Tools, Services and check that both the SMTP server and the Visendo services are set to start automatically.

Anonymous said...

Forgot a couple of things on the previous update comment: In Step 5 of article, after creating the account(s) you need, before exiting the Visendo UI make sure you click on the "Start" button to start the Visendo service. And, with Step 7 in article - Be sure you wait a few minutes because it may actually take SEVERAL minutes for mail to get processed into the administrator@contoso.com mailbox. And, you can look in the "C:\Inetpub\mailroot\Drop" folder where after sending a test email to yourself you should be able to almost immediately see the *.eml file sitting there for awhile (don't touch it) before it gets moved into the recipient's folder.

(In Windows Live Mail, you will probably want to go into Options and change the "Check for new messages every 10 minutes" default value to every 1 minute.)

Jeremias said...

Hi,
great article!
As you have mentioned Visendo SMTP Extender, it is in fact not necessary to edit the config file manually. You can completely configure it via the admin UI.
You can download the latest setup here:
http://www.visendo.com/VisendoDownloads.aspx?id=42

Further information on the product page (http://visendo.de/smtpextender.aspx) or in the manual.

Kind Regards
Jeremias Müller
Visendo Software

Briana Cooper said...

Thaanks for a great read