1. Products
  2.   Email
  3.   .NET
  4.   Postal
 
  

C# .NET Library to Generate, Send & Handle Emails

Open Source .NET API that Sends Emails for ASP.NET MVC using the View Engine. Add Content to an Email Message, Preview the Created Emails, Add Attachments, Embed Images & so on.

What is Postal?

Postal is a very useful C# .NET email library that enables software developers to generate and handle email messages with ease using a couple of lines of .NET code. It uses existing MVC views to generate emails. Most web apps need to send email messages in different ways and the Postal library makes their job easy by providing them all the necessary functions. The library is open source and is freely available under the MIT license.

The Postal library can work with any ASP.NET MVC view engine. The headers and body content can be easily identified by the email view. It has included support for several important features related to email management such as creating and sending HTML or plain-text email messages, adding attachments, embedding images, strongly type emails support, email headers support, creating emails without sending, preview generated email messages and many more.

Previous Next

Getting Started with Postal

The easiest way to install Postal is via NuGet. You can Install Postal into your ASP.NET web application using Nuget, please enter the following command.

install Postal via NuGet

Install-Package Postal.Mvc5 

You can also download it from GitHub and manually install it with ease.

Create & Send Emails via .NET API

The Open Source API Postal library enables software developers to create and send email messages with just a couple of lines of .NET code. The library has included support for both rich HTML and plain text versions. To create an email first create the main view which will include headers and reference the view to use. After that create the text view and specify a single content-type header. Lastly, create the HTML view with a single content-type header. The library supports features like sending email messages to multiple users, attaching files, image embedding, and much more.

How to Send Email Message using C# .NET API?

using Postal;

namespace App.Controllers {

    public class ExampleController : Controller
    {
        public ActionResult Send(string message)
        {
            dynamic email = new Email("Example");
            email.To = "test@example.com";
            email.Message = message;
            email.Send();

            return RedirectToAction("Sent");
        }
    }
} 

Preview Generated Emails before Sending

It is very beneficial to preview the created emails in the browser before sending it. Moreover, sometimes users don’t want to send out a mail each time they have made some changes to a template. The Open Source Postal library has provided functionality for previewing the generated email messages inside their .NET applications. . The ActionResult class can be used which simply renders the user’s template to the browser.

How to Previewe Generated Emails inside .NET Applications?

public class PreviewConroller : Controller 
{
    public ActionResult Example()
    {
        dynamic email = new Email("Example");
        // set up the email ...

        return new EmailViewResult(email);
    }
} 

Embedding Images into Emails via C# API

The Postal library has provided complete functionality for handling various types of images inside email messages using C# .NET API. It allows software developers to embed images directly into their email messages, enhancing their visual appeal with just a couple of lines of code. Here's a code example that shows how easily software developers can embed images inside their own C# applications. Here's is a simple example that shows how software developers can embed images inside their email messages using C# .NET API.

How to Embed Images inside Email Messages using .NET API?

email.Body = "

Here's an embedded image:

"; email.EmbedImage("logo", "path/to/image.png"); // Embedding image with content ID
 English