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

Open Source .NET MIME Creation & Parsing Library 

.NET MIME Creation and Parser Library for message Encryption, Decryption, and Signing as well as verifying Digital Signatures using S/MIME or OpenPGP Standards. 

MimeKit is an Open Source C# .NET library that enables software developers to create and parse email messages using the Multipurpose Internet Mail Extension (MIME). The main reason behind the development of the project was that it has been felt that the majority of email client (and server) software had less-than-satisfactory MIME implementations. Most of the times these email clients would incorrectly try to parse a MIME message and thus will not be able to get the full benefits that MIME.

The main aim of the MimeKit project is to address all these issues by as closely as possible and at the same time also provide computer programmers a tremendously easy to use high-level API. The great thing about the library is that it is much faster with all the available solutions. Even some commercial MIME parsers are not even come close to matching MimeKit's performance.

Previous Next

Getting Started with MimeKit

The easiest way to install MimeKit is through NuGet.  In Visual Studio's Package Manager Console, enter the following command

You can install it using pip.

install via NuGet

 Install-Package MimeKit 

Install via GitHub 

git clone --recursive https://github.com/jstedfast/MailKit.git 

.NET API to Create New Messages

The Open Source API MailKit library enables software developers to create MIME messages with few simple commands. A TextPart is a leaf-node MIME part with a text media-type. The first argument to the TextPart constructor specifies the media-subtype, in this case, plain. Another media subtype you are probably familiar with is the HTML subtype. The easiest way for both get and set the string content of the MIME part is the Text property.

Open Source API to Create Message - C#

var message = new MimeMessage();
message.From.Add(new MailboxAddress("fred", "This email address is being protected from spam-bots. You need JavaScript enabled to view it."));
message.To.Add(new MailboxAddress("frans", "This email address is being protected from spam-bots. You need JavaScript enabled to view it."));
message.Subject = "FileFormat ";

message.Body = new TextPart("plain")
{
  Text = "File Format Developer Guide"
};                 
                

Generate Message with Attachments using .NET API

MailKit API provides features for generating a message with attachments inside .NET applications.  Attachments are just like any other MimePart, the main difference is that they contain a content-disposition header holding value of the attachment instead of inline or no Content-Disposition header at all. To send out both a text/HTML and a text/plain version of the message, you need to create a TextPart for each part and then add them to a multipart/alternative.

Generate Email Attachments Free using C#

var message = new MimeMessage();
message.From.Add(new MailboxAddress("fred", "This email address is being protected from spam-bots. You need JavaScript enabled to view it."));
message.To.Add(new MailboxAddress("frans", "This email address is being protected from spam-bots. You need JavaScript enabled to view it."));
message.Subject = "FileFormat";
var path = "image.png";
var body =  message.Body = new TextPart("plain")
{
  Text = "File Format Developer Guide"
};

// create an image attachment for the file located at path
var attachment = new MimePart("image", "gif")
{
  Content = new MimeContent(File.OpenRead(path), ContentEncoding.Default),
  ContentDisposition = new ContentDisposition(ContentDisposition.Attachment),
  ContentTransferEncoding = ContentEncoding.Base64,
  FileName = System.IO.Path.GetFileName(path)
};

// now create the multipart/mixed container to hold the message text and the
// image attachment
var multipart = new Multipart("mixed")
{
  body,
  attachment
};

// now set the multipart/mixed as the message body
message.Body = multipart;                 
                

Encrypt or Decrypt Messages with S/MIME

The Open Source MailKit API provides features for encrypting messages using S/MIME cryptography context. S/MIME uses an application/pkcs7-mime MIME part to encapsulate encrypted content.  Create the message body with the message text and some image attachments.  After that, you can encrypt the message body using the custom S/MIME cryptography context.

 English