Configuring Email For Development Server

In this article we can explore how to configure Email for a Development Server. In real-world development envirnments you need to work with Email enabled lists / workflows / code.

Scenario

Your customer reported a problem with sending Email from a web part you have developed. You need to ensure the piece of code works fine in your development machine. Since there is not an email server configured in your machine – How to test this code?

Solution

We can set up a Development Server with emailing enabled. Setting up Email for the Development Server along with a Receiver tool you can ensure that emailing code is working perfectly.

Steps

The following are the steps involved:

  1. Configure outgoing SMTP server
  2. Set Email property for User Profiles
  3. Install smtp4dev tool
  4. Test Email Code

Please note that I am using a Windows 7 64-bit machine for working with this. The same configurations should work for Windows Server development machine.

Configure outgoing SMTP server

Open Central Administration and click on the System Settings category from the left.

Configure-outgoing-SMTP-server.jpg

In the page that appears click on the Configure outgoing e-mail settings link highlighted above. You should get the page given below.

Configure-outgoing-e-mail-settings-link.jpg

Enter the Outbound SMTP server as your machine name. Please enter a name instead of IP Address or localhost.

Enter the From and Reply-To address.

Click the OK button to save the changes.

Set Email property for User Profiles

As the next step we need to set the user profile property E-mail for testing the feature. You can set this through:

  1. My Profile of each user
  2. Central Administration for all users

Let us use the Central Administration way as we can set for multiple users. Open Central Administration > Manage service applications > Select User Profile Service Application > Click Manage button from toolbar.

Click-Manage-button-from-toolbar.jpg

In the page that appears click on the Manage User Profiles link as highlighted below:

Manage-User-Profiles-link.jpg

In the page that appears search for user and from the result choose Edit menu item.

choose-Edit-menu-item.jpg

In the Edit profile page set the Work-email property and save changes.

Work-email-property.jpg

Install smtp4dev tool

Now we can try installing the smtp4dev tool (a wonderful tool) that captures the Port 25 of your machine. You can download the tool from the following location:

http://smtp4dev.codeplex.com/

Click the Download button on the page that appears.

Install-smtp4dev-tool.jpg

Run the downloaded file and you should see the following screen:

smtp4dev-tool.jpg

By default the tool begins to listen on Port 25. You can minimize the tool and it is available in the system tray.

Note: Running another instance of the smtp4dev tool cannot listen to the same port 25. You need to invoke the previous copy of the tool from the system tray to view any email messages.

Test Email Code

Now we are ready to test the email code. Start a new SharePoint Console application, change the project properties to .Net Framework 3.5 and replace the Program class content with the following code:

using System.Collections.Specialized;

using System.Collections.Specialized; 

class Program

{

    static void Main(string[] args)

    {

        using (SPSite site = new SPSite("http://localhost"))

        {

            StringDictionary messageHeaders = new StringDictionary();

            messageHeaders.Add("to", "[email protected]");

            messageHeaders.Add("cc", "[email protected]");

            messageHeaders.Add("from", "[email protected]");

            messageHeaders.Add("subject", "Email Subject");

            messageHeaders.Add("content-type", "text/html");

 

            SPUtility.SendEmail(site.OpenWeb(), messageHeaders, "Email Body");

        }

    }

}

For the time being we are using a dummy email address. Try executing the code. You will see the email being captured by the smtp4dev tool.

Test -Email-Code.jpg

References

http://tinyurl.com/sp2010-confemail

Summary

In this article we have explored how to configure an email server for a development machine and use the smtp4dev tool to capture the emails generated from the machine. You can use the same configuration to test other emails through Workflows, Web Parts etc. that are generated through SharePoint.

Please note that here we are setting up a development machine email server and for configuring the actual email service you need to check the link from the References section.