Install MsgKit via NuGet
masterThe easiest way to install MsgKit is via the NuGet package manager. Use the following command in the Visual Studio Package Manager Console:
Install-Package MsgKitrepository·master·Indexed 42 days ago
https://github.com/sicos1977/msgkitA fully managed C# .NET library for creating Outlook-compatible messages, including E-Mails, Appointments, Contact cards, and Tasks, without requiring P/Invoke or COM interop.
The easiest way to install MsgKit is via the NuGet package manager. Use the following command in the Visual Studio Package Manager Console:
Install-Package MsgKitUse the Email class to construct an email message. You can specify a Sender, a Representing user, recipients (To/Cc), subject, body (Text or HTML), importance, and attachments. The class implements IDisposable, so it should be wrapped in a using block. Call .Save(path) to write the .msg file to disk.
using (var email = new Email(
new Sender("peterpan@neverland.com", "Peter Pan"),
new Representing("tinkerbell@neverland.com", "Tinkerbell"),
"Hello Neverland subject"))
{
email.Recipients.AddTo("captainhook@neverland.com", "Captain Hook");
email.Recipients.AddCc("crocodile@neverland.com", "The evil ticking crocodile");
email.Subject = "This is the subject";
email.BodyText = "Hello Neverland text";
email.BodyHtml = "<html><head></head><body><b>Hello Neverland html</b></body></html>";
email.Importance = MessageImportance.IMPORTANCE_HIGH;
email.IconIndex = MessageIconIndex.ReadMail;
email.Attachments.Add(@"d:\crocodile.jpg");
email.Save(@"c:\email.msg");
}Use the Contact class to create detailed contact information. This includes complex nested objects for Assistant, ContactCompanyMain, ContactWork, ContactBusiness, ContactHome, and ContactOther. You can also set a ContactPicture using a byte array and manage multiple email addresses via Address objects.
using (var contact = new Contact(
new Sender(SenderTextBox.Text, string.Empty),
SubjectTextBox.Text,
DraftMessageCheckBox.Checked,
ReadReceiptCheckBox.Checked))
{
contact.Recipients.AddTo("captainhook@neverland.com", "Captain Hook");
contact.Subject = "This is the subject";
contact.BodyText = "Hello Neverland text";
contact.BodyHtml = "<html><head></head><body><b>Hello Neverland html</b></body></html>";
contact.Importance = MessageImportance.IMPORTANCE_NORMAL;
contact.FileUnder = "File under";
contact.BirthDay = DateTime.Now;
contact.WeddingAnniversary = DateTime.Now;
contact.Assistant = new ContactAssistant {Name = "Assistant name", TelephoneNumber = "Assistant telephone number"};
contact.CompanyMain = new ContactCompanyMain { Name = "Company main name", TelephoneNumber = "Company main telephone number"};
contact.Email1 = new Address("email1@neverland.com", "email1");
contact.Work = new ContactWork
{
TelephoneNumber = "Contact telephone number",
City = "Contact city",
Country = "Contact country",
Street = "Contact street",
Address = "Contact\nBla bla\nBla die bla\nBLa die bla die bla"
};
contact.ContactPicture = File.ReadAllBytes("Images\\tinkerbell.jpg");
contact.IconIndex = MessageIconIndex.UnsentMail;
contact.Save("c:\\contact.msg");
}Use the Appointment class to create calendar entries. Key properties include Location, MeetingStart, MeetingEnd, AllDay, and BodyText/BodyHtml. Like the Email class, it is disposable and requires a .Save(path) call.
using (var appointment = new Appointment(
new Sender("peterpan@neverland.com", "Peter Pan"),
new Representing("tinkerbell@neverland.com", "Tinkerbell"),
"Hello Neverland subject"))
{
appointment.Recipients.AddTo("captainhook@neverland.com", "Captain Hook");
appointment.Recipients.AddCc("crocodile@neverland.com", "The evil ticking crocodile");
appointment.Subject = "This is the subject";
appointment.Location = "Neverland";
appointment.MeetingStart = DateTime.Now.Date;
appointment.MeetingEnd = DateTime.Now.Date.AddDays(1).Date;
appointment.AllDay = true;
appointment.BodyText = "Hello Neverland text";
appointment.BodyHtml = "<html><head></head><body><b>Hello Neverland html</b></body></html>";
appointment.SentOn = DateTime.UtcNow;
appointment.Importance = MessageImportance.IMPORTANCE_NORMAL;
appointment.IconIndex = MessageIconIndex.UnsentMail;
appointment.Attachments.Add(@"d:\crocodile.jpg");
appointment.Save(@"c:\appointment.msg");
}Use the MsgKit.Task class to create task items. You can configure Status (e.g., TaskStatus.NotStarted), Complete (boolean), PercentageComplete, DueDate, StartDate, and Mode (e.g., TaskMode.Accepted). It supports RTF body content via BodyRtf and standard text/HTML bodies. Attachments can be added with custom names and flags.
using (var task = new MsgKit.Task(
new MsgKit.Sender("peterpan@neverland.com", "Peter Pan"),
new MsgKit.Representing("tinkerbell@neverland.com", "Tinkerbell"),
"Hello Neverland subject"))
{
task.Recipients.AddTo("captainhook@neverland.com", "Captain Hook");
task.Subject = "This is the subject";
task.Status = MsgKit.Enums.TaskStatus.NotStarted;
task.Complete = false;
task.PercentageComplete = 0.0;
task.DueDate = DateTime.Now.Date.AddDays(1).Date;
task.StartDate = DateTime.Now.Date;
task.Mode = MsgKit.Enums.TaskMode.Accepted;
task.BodyRtf = @"{\rtf1\ansi\deff0{\colortbl;\red0\green0\blue0;\red255\green0\blue0;}" +
@"This line is the default color\line\cf2This line is red\line\cf1" +
@"This line is the default color}";
task.BodyText = "Hello Neverland text";
task.BodyHtml = "<html><head></head><body><b>Hello Neverland html</b></body></html>";
task.Importance = MsgKit.Enums.MessageImportance.IMPORTANCE_NORMAL;
task.Attachments.Add("Images\\peterpan.jpg");
task.Attachments.Add("Images\\tinkerbell.jpg", -1, true, "tinkerbell.jpg");
task.Save(@"d:\Task.msg");
}