Understanding SMTP4Dev and SendGrid For SMTP Solutions

When developing an application we often get stuck because of some configuration settings such as SMTP server. This may increase the development time as well as the deliveries. Our deliveries should not be affected because of these details.

For example, you get the task of implementing two-way authentication, sending notifications and updates or any other task that requires SMTP details for a project. You are supposed to complete the task since it is effecting other modules in the application but you didn't receive the SMTP details. Before getting the actual details you can use a tool in market that acts as a local SMTP.

The following are some tools available in the market.

  1. Paper cut
  2. Fake SMTP
  3. Smtp4Dev

Apart from the preceding tools we can also use the Sendgrid service to send email. It's available in your Azure subscription (marketplace) and has a plan that allows users to send 25,000 emails per month. We will see it in detail in a later part of the article.

In this article, we will first learn about the SMTP4Dev tool and its options, then we will see how to configure SendGrid from your Azure subscription. In the final section we will explain the implementation of the SMTP4Dev tool and SendGrid service.

SMTP4Dev

Here we will talk about the SMTP4dev that is available in codeplex.com. Please visit the following link.

https://smtp4dev.codeplex.com/

Download the application from codeplex.com, extract and run it. This will get placed on your computer system tray and look as in the following image.


Figure 1: SMTP4Dev

You can use many settings, such as SSL, max message size, server name or IP and so on.


Figure 2: Server Name

Once you set up all the options depending on the requirements, then write C# code to send the emails.

SendGrid

In the Azure market place you can find a nice service for sending emails, SendGrid. It is a powerful cloud based service that sends emails on behalf of companies.

It has some pricing factor, check the following link for more details.

http://azure.microsoft.com/en-in/marketplace/partners/sendgrid/sendgrid-azure/

If you have an Azure subscription you can use the free plan that offers 25000 emails per month.

Let's develop an application that will use both SMTP4Dev and Send grid to send emails. For SMTP4Dev we don't need to configure much, just download it and use it.

But for SendGrid use the following procedure to use the Azure subscription.

Step 1

Select New from the command bar as in Figure 3.


Figure 3: Command Bar

Step 2

Select Marketplace. In Marketplace select developer services there in the right blade you will find SendGrid.


Figure 4: Send Grid

Step 3

Click on create, it will create the service and pin it to the storyboard.


Figure 5: Create a New Send Account

Click on the sendgrid tile in the home dashboard. It will open a blad that shows more information about your SendGrid service. In the following image you can see the two settings:

  1. Properties that provides details regarding the service such as its status, provider, pricing plan and subscription id.
  2. Configurations that gives you the username and password and SMTP server details.


Figure 6: Send Grid Demo

Demo/Application

Once this setup is done we can now move to the final section of the article, in other words the application/demo part where we will create a simple WPF application with the three textboxes, From-email, To-email and the last one is for the message or the email body. Now take two buttons, one to send using send grid and the other one is configured to receive messages using SMTP4Dev.

Let's walk through our application. I will attach the code with the article, so you can also download the stuff.

The solution contains two projects, one for the email service and the other one is the WPF application.


Figure 7: Solution Contain

Let's check the Email service code that is our main interest here. I have defined an Interface name IEmail service as in Figure 8.


Figure 8: Service Code

We have two concrete classes SendGridDemo and SMTP4Dev, the only difference is their Send method. First we will see the SMTP4Dev send method.


Figure 9: SMTP4Dev Send Method

This is pretty simple code that only uses “System.Net.Mail”. This piece of code is very common that we generally use to send email using a SMTP server. So the point here is we don't need to rewrite the code again for the actual live SMTP server configuration changes; just make a few changes and we are done.

SMTP4Dev also acts as a SMTP server, but locally. Here we can do our development and even testing.

For SendGrid, the first thing we need to do is add a Nugget package named SendGrid as in Figure 10. I already installed it in my project.


Figure 10: Manage Nuget Package

After installing the package for SendGrid we need to add the following piece of code in the Send method of the SendGridDemo class as in Figure 11.


Figure 11: Code

For more details of SendGrid, visit the link.

The rest of the implementations are pretty easy, here you need to call the send methods. Download the working code attached.

Conclusion: You have seen the SMTP4dev tool that acts as a local SMTP server that you can use in our development environment and can complete our tasks. You have also seen SendGrid that is one of the powerful cloud-based solutions for sending emails. Now you don't need to wait for the details. We can start coding right away.

References

  1. https://smtp4dev.codeplex.com/
  2. http://azure.microsoft.com/en-in/marketplace/partners/sendgrid/sendgrid-azure/
  3. https://azure.microsoft.com/en-us/documentation/articles/sendgrid-dotnet-how-to-send-email/

Up Next
    Ebook Download
    View all
    Learn
    View all