Tuesday, 24 March 2015

How can I easily debug an email utility in SharePoint?

Working with emails (especially in Timer Service jobs) can be a pain to debug. Fortunately, there are a few freely available utilities that make this chore very simple.

I recently wrote a simple server that send numerous emails using the following code:

                        var headers = new StringDictionary
                            {"from", web.Site.WebApplication.OutboundMailSenderAddress},
                            {"to", user.Email},
                            {"subject", subject},
                            {"content-type", "text/html"}

                        SPUtility.SendEmail(web, headers, CreateEmailMessage());

I then downloaded the fantastic FakeSMTP to act as my SMTP server. This gem intercepts emails on the default mail port (25). Download the code and run 'java -jar fakeSTMP.jar'. (Be sure to start the server before you begin).

The next step is to configure SharePoint to use the local machine as its SMTP server.
In Central Administration -> System Settings, select 'Configure outgoing email settings'

Set the 'Outbound SMTP server' to the full name of your development machine. You can get the name from 'Control Panel\All Control Panel Items\System'

You are now in a position to retrieve the emails. The last piece of the puzzle is to download an eml viewer. I use FreeViewer.

NOTE: Remember to associate .eml files to this application or you will be prompted when double clicking on the email.

No comments:

Post a comment