### Install MsgKit via NuGet Source: https://context7.com/sicos1977/msgkit/llms.txt Use the NuGet Package Manager to install the MsgKit library into your .NET project. ```powershell Install-Package MsgKit ``` -------------------------------- ### Create and Save a Task in C# Source: https://github.com/sicos1977/msgkit/blob/master/README.md Use this snippet to create a new task, populate its fields with relevant information, and save it as a .msg file. Ensure the MsgKit library is referenced in your project. The code also includes an example of how to open the saved task. ```csharp 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.Recipients.AddCc("crocodile@neverland.com", "The evil ticking crocodile"); 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.Recurring = false; task.ReminderTime = DateTime.Now.Date; 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.BodyRtfCompressed = true; task.BodyText = "Hello Neverland text"; task.BodyHtml = "Hello Neverland html"; task.SentOn = DateTime.UtcNow; task.Importance = MsgKit.Enums.MessageImportance.IMPORTANCE_NORMAL; task.IconIndex = MsgKit.Enums.MessageIconIndex.UnsentMail; task.Attachments.Add("Images\\peterpan.jpg"); task.Attachments.Add("Images\\tinkerbell.jpg", -1, true, "tinkerbell.jpg"); task.Save(@"d:\\Task.msg"); // Show the appointment System.Diagnostics.Process.Start(@"d:\\Task.msg"); } ``` -------------------------------- ### Create a detailed contact card in C# Source: https://context7.com/sicos1977/msgkit/llms.txt Demonstrates how to instantiate a Contact object and populate it with various personal, professional, and address details before saving it to a file. ```csharp using MsgKit; using MsgKit.Enums; using System.IO; // Create a detailed contact card using (var contact = new Contact( new Sender("crm@example.com", "CRM System"), "John Smith")) { // Basic information contact.Subject = "John Smith"; contact.GivenName = "John"; contact.MiddleName = "Robert"; contact.SurName = "Smith"; contact.NickName = "Johnny"; contact.Title = "Senior Vice President"; contact.Initials = "JRS"; contact.Generation = "Jr."; contact.FileUnder = "Smith, John"; // Contact dates contact.BirthDay = new DateTime(1985, 6, 15); contact.WeddingAnniversary = new DateTime(2010, 9, 20); // Professional information contact.Profession = "Technology Executive"; contact.DepartmentName = "Information Technology"; contact.ManagerName = "Jane Doe"; contact.OfficeLocation = "Building A, Floor 5"; // Email addresses (up to 3) contact.Email1 = new Address("john.smith@example.com", "John Smith - Work"); contact.Email2 = new Address("jsmith@personal.com", "John Smith - Personal"); contact.Email3 = new Address("john@consulting.com", "John Smith - Consulting"); // Phone numbers contact.PrimaryTelephoneNumber = "+1-555-123-4567"; contact.MobileTelephoneNumber = "+1-555-987-6543"; contact.OfficeTelephoneNumber = "+1-555-111-2222"; contact.PrimaryFaxNumber = "+1-555-111-3333"; contact.PagerTelephoneNumber = "+1-555-999-8888"; contact.CarTelePhoneNumber = "+1-555-777-6666"; contact.CallBackTelePhoneNumber = "+1-555-444-5555"; // Company information contact.CompanyMain = new ContactCompanyMain { Name = "Acme Corporation", TelephoneNumber = "+1-555-000-0000" }; // Assistant information contact.Assistant = new ContactAssistant { Name = "Sarah Johnson", TelephoneNumber = "+1-555-222-3333" }; // Business address contact.Business = new ContactBusiness { Street = "123 Business Park Drive", City = "San Francisco", State = "CA", PostalCode = "94105", Country = "United States", TelephoneNumber = "+1-555-111-2222", FaxNumber = "+1-555-111-3333", HomePage = "https://www.acmecorp.com" }; // Home address contact.Home = new ContactHome { Street = "456 Residential Lane", City = "Palo Alto", State = "CA", PostalCode = "94301", Country = "United States", TelephoneNumber = "+1-555-444-5555", TelephoneNumber2 = "+1-555-444-5556", FaxNumber = "+1-555-444-5557" }; // Work address contact.Work = new ContactWork { Street = "789 Corporate Blvd", City = "Mountain View", PostalCode = "94043", Country = "United States", CountryCode = "US" }; // Other address contact.Other = new ContactOther { Street = "321 Vacation Road", City = "Lake Tahoe", State = "NV", PostalCode = "89449", Country = "United States" }; // Personal details contact.SpouseName = "Emily Smith"; contact.ChildrensNames = new List { "Michael", "Sarah", "David" }; contact.Language = "English"; contact.InstantMessagingAddress = "jsmith@messenger.com"; contact.PersonalHomePage = "https://johnsmith.personal.com"; contact.Private = false; // Yomi names (for Japanese sorting) contact.Yomi = new ContactYomi { FirstName = "Jon", LastName = "Sumisu", CompanyName = "Eikumukooporeeshon" }; // Set primary postal address contact.PostalAddressId = PostalAddressId.BUSINESS_ADDRESS; // Add contact photo (JPG format) contact.ContactPicture = File.ReadAllBytes(@"C:\Images\john-smith.jpg"); // Message properties contact.BodyText = "Senior Vice President at Acme Corporation. Primary contact for enterprise solutions."; contact.Importance = MessageImportance.IMPORTANCE_NORMAL; contact.IconIndex = MessageIconIndex.UnsentMail; contact.Save(@"C:\Output\john-smith-contact.msg"); } ``` -------------------------------- ### Create and Save Contact Card in C# Source: https://github.com/sicos1977/msgkit/blob/master/README.md This snippet shows how to instantiate a `Contact` object, populate its numerous properties with various details, and then save it to a .msg file. It also demonstrates how to open the saved file using the default application. ```csharp 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.Recipients.AddCc("crocodile@neverland.com", "The evil ticking crocodile"); contact.Subject = "This is the subject"; contact.BodyText = "Hello Neverland text"; contact.BodyHtml = "Hello Neverland html" contact.Importance = MessageImportance.IMPORTANCE_NORMAL; contact.FileUnder = "File under"; contact.InstantMessagingAddress = "Instant messaging address"; contact.Private = false; contact.BirthDay = DateTime.Now; contact.WeddingAnniversary = DateTime.Now; contact.Assistant = new ContactAssistant {Name = "Assistant name", TelephoneNumber = "Assistant telephone number"}; contact.CallBackTelePhoneNumber = "callback telephone number"; contact.CarTelePhoneNumber = "car telephone number"; contact.ChildrensNames = new List {"First child name", "Second child name", "Third child name"}; contact.CompanyMain = new ContactCompanyMain { Name = "Company main name", TelephoneNumber = "Company main telephone number"}; contact.DepartmentName = "Department name"; contact.Generation = "Generation"; contact.GivenName = "GivenName"; contact.Initials = "Initials"; contact.ISDNNumber = "ISDN number"; contact.Language = "Language"; contact.Location = "Location"; contact.ManagerName = "Manager name"; contact.MiddleName = "Middle name"; contact.MobileTelephoneNumber = "Mobile telephone number"; contact.NickName = "Nick name"; contact.OfficeLocation = "Office location"; contact.PersonalHomePage = "Personal home-page"; contact.PostalAddress = "Postal address"; contact.PrimaryFaxNumber = "Primary fax number"; contact.PrimaryTelephoneNumber = "Primary telephone number"; contact.Profession = "Profession"; contact.RadioTelephoneNumber = "Radio telephone number"; contact.SpouseName = "Spouse name"; contact.SurName = "Sur name"; contact.TelexNumber = "Telex number"; contact.Title = "Title"; contact.TTYTDDPhoneNumber = "TTYTDD phone number"; contact.Email1 = new Address("email1@neverland.com", "email1"); contact.Email2 = new Address("email2@neverland.com", "email2"); contact.Email3 = new Address("email3@neverland.com", "email3"); //contact.Fax1 = "fax1@1234567890"; //contact.Fax2 = "fax2@1234567890"; //contact.Fax3 = "fax3@1234567890"; contact.OfficeTelephoneNumber = "Office telephone number"; contact.InstantMessagingAddress = "Instant messaging address"; contact.Yomi = new ContactYomi { CompanyName = "Yomi company name", FirstName = "Yomi first name", LastName = "Yomi last name"}; contact.Work = new ContactWork { TelephoneNumber = "Contact telephone number", City = "Contact city", Country = "Contact country", CountryCode = "Contact country code", PostOfficeBox = "Contact post office box", PostalCode = "Contact postal code", Street = "Contact street", Address = "Contact\nBla bla\nBla die bla\nBLa die bla die bla" }; contact.Business = new ContactBusiness { TelephoneNumber = "Business telephone number", FaxNumber = "Business fax number", HomePage = "Business home-page", City = "Business city", Country = "Business country", PostalCode = "Business postal code", State = "Business state", Street = "Business street", Address = "Business\nBla bla\nBla die bla\nBLa die bla die bla" }; contact.Home = new ContactHome { TelephoneNumber = "Home telephone number", TelephoneNumber2 = "Home telephone number 2", FaxNumber = "Home faxnumber", City = "Home city", Country = "Home country", PostalCode = "Home postal code", State = "Home state", Street = "Home street", Address = "Home\nBla bla\nBla die bla\nBLa die bla die bla" }; contact.Other = new ContactOther { TelephoneNumber = "Other telephone number", City = "Other city", Country = "Other country", PostalCode = "Other postal code", State = "Other state", Street = "Other street", Address = "Other\nBla bla\nBla die bla\nBLa die bla die bla" }; contact.PagerTelephoneNumber = "Pager telephone number"; contact.PostalAddressId = PostalAddressId.HOME_ADDRESS; contact.ContactPicture = File.ReadAllBytes("Images\\tinkerbell.jpg"); contact.IconIndex = MessageIconIndex.UnsentMail; contact.Save("c:\\contact.msg"); System.Diagnostics.Process.Start("c:\\Contact.msg"); } ``` -------------------------------- ### Create an Appointment with MsgKit Source: https://github.com/sicos1977/msgkit/blob/master/README.md Shows how to create and save an Outlook-compatible appointment using MsgKit. This includes setting sender, attendees, subject, location, start/end times, all-day status, body content, and saving to a .msg file. ```csharp 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 = "Hello Neverland 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"); // Show the Appointment System.Diagnostics.Process.Start(@"c:\\Appointment.msg"); } ``` -------------------------------- ### Create an E-mail with MsgKit Source: https://github.com/sicos1977/msgkit/blob/master/README.md Demonstrates how to create and save an Outlook-compatible email message using MsgKit. Includes setting recipients, subject, body (text and HTML), importance, icon, attachments, and saving the message to a .msg file. ```csharp 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 = "Hello Neverland html"; email.Importance = MessageImportance.IMPORTANCE_HIGH; email.IconIndex = MessageIconIndex.ReadMail; email.Attachments.Add(@"d:\\crocodile.jpg"); email.Save(@"c:\\email.msg"); // Show the E-mail System.Diagnostics.Process.Start(@"c:\\Email.msg"); } ``` -------------------------------- ### Create a Meeting Appointment in C# Source: https://context7.com/sicos1977/msgkit/llms.txt Use this snippet to create a detailed meeting appointment with attendees, subject, location, time, and body content. Ensure all necessary MsgKit namespaces are included. ```csharp using MsgKit; using MsgKit.Enums; // Create a meeting appointment using (var appointment = new Appointment( new Sender("organizer@example.com", "Meeting Organizer"), new Representing("department@example.com", "Sales Department"), "Quarterly Sales Review")) { // Add attendees appointment.Recipients.AddTo("manager@example.com", "Sales Manager"); appointment.Recipients.AddTo("rep1@example.com", "Sales Rep 1"); appointment.Recipients.AddCc("assistant@example.com", "Admin Assistant"); // Set appointment details appointment.Subject = "Q4 Sales Performance Review"; appointment.Location = "Conference Room A - Building 1"; appointment.MeetingStart = new DateTime(2024, 12, 15, 14, 0, 0); appointment.MeetingEnd = new DateTime(2024, 12, 15, 15, 30, 0); appointment.AllDay = false; // Set body content appointment.BodyText = "Quarterly sales review meeting to discuss Q4 performance and Q1 targets."; appointment.BodyHtml = @"

Meeting Agenda

"; appointment.Importance = MessageImportance.IMPORTANCE_HIGH; appointment.SentOn = DateTime.UtcNow; // Add meeting materials appointment.Attachments.Add(@"C:\Documents\sales-report.pptx"); appointment.Save(@"C:\Output\sales-review.msg"); } ``` -------------------------------- ### Create an All-Day Event in C# Source: https://context7.com/sicos1977/msgkit/llms.txt This snippet demonstrates how to create an all-day calendar event, such as a holiday. Times should be set to midnight, and the 'AllDay' property must be true. ```csharp using MsgKit; using MsgKit.Enums; // Create an all-day event using (var allDayEvent = new Appointment( new Sender("hr@example.com", "Human Resources"), "Company Holiday - New Year's Day")) { allDayEvent.Subject = "Office Closed - New Year's Day"; allDayEvent.Location = "Company-wide"; allDayEvent.MeetingStart = new DateTime(2025, 1, 1, 0, 0, 0); allDayEvent.MeetingEnd = new DateTime(2025, 1, 2, 0, 0, 0); allDayEvent.AllDay = true; allDayEvent.BodyText = "The office will be closed for New Year's Day."; allDayEvent.Importance = MessageImportance.IMPORTANCE_NORMAL; allDayEvent.Save(@"C:\Output\new-years-holiday.msg"); } ``` -------------------------------- ### Create a Basic Email Message Source: https://context7.com/sicos1977/msgkit/llms.txt Create a basic email message with sender, recipients, subject, body content in plain text and HTML, attachments, and message properties. Ensure to close the email object using a 'using' statement for proper resource management. ```csharp using MsgKit; using MsgKit.Enums; // Create a basic email message using (var email = new Email( new Sender("sender@example.com", "Sender Name"), "Important Meeting Tomorrow")) { // Add recipients email.Recipients.AddTo("recipient@example.com", "Recipient Name"); email.Recipients.AddCc("manager@example.com", "Manager Name"); email.Recipients.AddBcc("archive@example.com", "Archive"); // Set message content email.Subject = "Important Meeting Tomorrow"; email.BodyText = "Please join us for an important meeting tomorrow at 10 AM."; email.BodyHtml = @"

Meeting Reminder

Please join us for an important meeting tomorrow at 10 AM.

"; // Set message properties email.Importance = MessageImportance.IMPORTANCE_HIGH; email.Priority = MessagePriority.PRIO_URGENT; email.SentOn = DateTime.UtcNow; // Add file attachment email.Attachments.Add(@"C:\Documents\agenda.pdf"); // Add inline image (for HTML body) email.Attachments.Add(@"C:\Images\logo.png", -1, true, "logo-image"); // Save the message email.Save(@"C:\Output\meeting-reminder.msg"); } ``` -------------------------------- ### Create an Outlook Task with MsgKit Source: https://context7.com/sicos1977/msgkit/llms.txt Initializes a Task object with sender, recipient, and detailed status tracking properties. Requires the MsgKit and MsgKit.Enums namespaces. ```csharp using MsgKit; using MsgKit.Enums; // Create a comprehensive task using (var task = new Task( new Sender("manager@example.com", "Project Manager"), new Representing("team@example.com", "Development Team"), "Complete Project Documentation")) { // Task recipients task.Recipients.AddTo("developer@example.com", "Lead Developer"); task.Recipients.AddCc("qa@example.com", "QA Lead"); // Basic task properties task.Subject = "Complete API Documentation for v2.0 Release"; task.Owner = "Lead Developer"; // Status and progress task.Status = TaskStatus.InProgress; task.PercentageComplete = 45.0; task.Complete = false; // Dates task.StartDate = DateTime.Now.Date; task.DueDate = DateTime.Now.Date.AddDays(14); task.CommonStart = DateTime.Now.Date; task.CommonEnd = DateTime.Now.Date.AddDays(14); // Effort tracking task.EstimatedEffort = TimeSpan.FromHours(40); task.ActualEffort = TimeSpan.FromHours(18); // Assignment and state task.Mode = TaskMode.Accepted; task.State = TaskState.Accepted; task.Ownership = TaskOwnership.AssigneesCopy; task.AcceptanceState = TaskAcceptanceState.Accepted; task.Assigner = "Project Manager"; task.TeamTask = false; task.Version = 1; // Request updates task.Updates = true; task.StatusOnComplete = true; // Reminder settings task.ReminderTime = DateTime.Now.Date.AddDays(12).AddHours(9); task.ReminderDelta = 15; task.ReminderSignalTime = DateTime.Now.Date.AddDays(12).AddHours(8).AddMinutes(45); // Recurrence (false for one-time task) task.Recurring = false; // Ordering for to-do list task.ToDoOrdinalDate = DateTime.UtcNow; task.ToDoSubOrdinal = "5555555"; task.Ordinal = 1000; // Task body content task.BodyText = @"Complete the following documentation tasks: 1. API endpoint reference 2. Authentication guide 3. Code examples 4. Migration guide from v1.x"; task.BodyHtml = @"

Documentation Tasks

  1. API endpoint reference
  2. Authentication guide
  3. Code examples
  4. Migration guide from v1.x
"; // RTF body (optional, compressed) task.BodyRtf = @"{\rtf1\ansi\deff0{\colortbl;\red0\green0\blue0;\red255\green0\blue0;}" + @"Documentation task list\line\cf2Priority: High\line\cf1" + @"Please complete by the due date.}"; task.BodyRtfCompressed = true; task.Importance = MessageImportance.IMPORTANCE_HIGH; task.SentOn = DateTime.UtcNow; task.IconIndex = MessageIconIndex.UnsentMail; // Add attachments task.Attachments.Add(@"C:\Templates\documentation-template.docx"); task.Save(@"C:\Output\api-documentation-task.msg"); } ``` -------------------------------- ### Create Email with Read Receipt Request Source: https://context7.com/sicos1977/msgkit/llms.txt Create an email message that requests a read receipt from the recipient. This allows tracking when the recipient opens the message. Ensure the 'readReceipt' parameter is set to true. ```csharp using MsgKit; // Create email with read receipt request using (var email = new Email( new Sender("sender@example.com", "Sender"), "Delivery Confirmation Required", draft: false, readReceipt: true)) { email.Recipients.AddTo("recipient@example.com", "Recipient"); email.BodyText = "Please confirm receipt of this important message."; email.Save(@"C:\Output\receipt-requested.msg"); } ``` -------------------------------- ### Save MSG to Stream (C#) Source: https://context7.com/sicos1977/msgkit/llms.txt Demonstrates saving an email to a MemoryStream for further processing or to a FileStream for direct file creation. Ensure proper disposal of streams. ```csharp using MsgKit; using System.IO; // Save to MemoryStream for further processing using (var email = new Email( new Sender("sender@example.com", "Sender"), "Stream-based Email")) { email.Recipients.AddTo("recipient@example.com", "Recipient"); email.BodyText = "This email is saved to a stream."; using (var memoryStream = new MemoryStream()) { email.Save(memoryStream); // Get the bytes for upload, storage, etc. var msgBytes = memoryStream.ToArray(); // Example: Upload to cloud storage // await cloudStorage.UploadAsync("email.msg", msgBytes); // Example: Return in web response // return File(msgBytes, "application/vnd.ms-outlook", "email.msg"); } } // Save directly to FileStream with specific options using (var email = new Email( new Sender("sender@example.com", "Sender"), "FileStream Email")) { email.Recipients.AddTo("recipient@example.com", "Recipient"); email.BodyText = "Saved with FileStream."; using (var fileStream = new FileStream( @"C:\\Output\\stream-email.msg", FileMode.Create, FileAccess.Write, FileShare.None)) { email.Save(fileStream); } } ``` -------------------------------- ### Manage Email Recipients with MsgKit Source: https://context7.com/sicos1977/msgkit/llms.txt Use the Recipients class to add To, Cc, Bcc, and Reply-To addresses, or configure specific MAPI properties for recipients. ```csharp using MsgKit; using MsgKit.Enums; using (var email = new Email( new Sender("sender@example.com", "Sender Name"), "Email to Multiple Recipients")) { // Add To recipients (primary recipients) email.Recipients.AddTo("primary@example.com", "Primary Recipient"); email.Recipients.AddTo("secondary@example.com", "Secondary Recipient"); // Add Cc recipients (carbon copy) email.Recipients.AddCc("manager@example.com", "Manager"); email.Recipients.AddCc("team@example.com", "Team Lead"); // Add Bcc recipients (blind carbon copy) email.Recipients.AddBcc("archive@example.com", "Archive System"); email.Recipients.AddBcc("compliance@example.com", "Compliance Team"); // Add recipient with full control over properties email.Recipients.AddRecipient( email: "external@partner.com", displayName: "External Partner", addressType: AddressType.Smtp, recipientType: RecipientType.To, objectType: MapiObjectType.MAPI_MAILUSER, displayType: RecipientRowDisplayType.MessagingUser); // Add reply-to recipients (separate from To/Cc/Bcc) email.ReplyToRecipients.AddTo("replies@example.com", "Reply Handler"); email.BodyText = "This email demonstrates various recipient types."; email.Save(@"C:\Output\multi-recipient-email.msg"); } ``` -------------------------------- ### Add Attachments to Email Messages Source: https://context7.com/sicos1977/msgkit/llms.txt Demonstrates adding files, streams, and linked references to an Email object. Supports inline images via content IDs and rendering positions. ```csharp using MsgKit; using System.IO; using (var email = new Email( new Sender("sender@example.com", "Sender"), "Email with Various Attachments")) { email.Recipients.AddTo("recipient@example.com", "Recipient"); email.BodyHtml = @"

Please see the attachments below:

Company Logo

Best regards

"; // Add attachment from file path email.Attachments.Add(@"C:\Documents\report.pdf"); // Add attachment from file path with rendering position email.Attachments.Add(@"C:\Documents\spreadsheet.xlsx", renderingPosition: 0); // Add inline attachment (for HTML images) email.Attachments.Add( @"C:\Images\logo.png", renderingPosition: -1, isInline: true, contentId: "company-logo"); // Add attachment from stream using (var memoryStream = new MemoryStream()) { // Write some data to the stream var data = System.Text.Encoding.UTF8.GetBytes("Dynamic content generated at runtime"); memoryStream.Write(data, 0, data.Length); memoryStream.Position = 0; email.Attachments.Add( memoryStream, "dynamic-content.txt", renderingPosition: -1, isInline: false); } // Add attachment as a link (UNC path reference) var linkedFile = new FileInfo(@"\\server\share\large-file.zip"); email.Attachments.AddLink(linkedFile); email.Save(@"C:\Output\email-with-attachments.msg"); } ``` -------------------------------- ### Convert MSG to EML Files Source: https://context7.com/sicos1977/msgkit/llms.txt Convert existing MSG files back to standard EML (MIME) format for interoperability. ```csharp using MsgKit; using System.IO; // Convert MSG file to EML file Converter.ConvertMsgToEml( msgFileName: @"C:\Input\email.msg", emlFileName: @"C:\Output\email.eml"); // Convert using streams using (var msgStream = new FileStream(@"C:\Input\email.msg", FileMode.Open, FileAccess.Read)) using (var emlStream = new FileStream(@"C:\Output\email.eml", FileMode.Create)) { Converter.ConvertMsgToEml(msgStream, emlStream); } // Batch conversion example var msgFiles = Directory.GetFiles(@"C:\Input", "*.msg"); foreach (var msgFile in msgFiles) { var emlFile = Path.ChangeExtension(msgFile, ".eml"); emlFile = Path.Combine(@"C:\Output", Path.GetFileName(emlFile)); Converter.ConvertMsgToEml(msgFile, emlFile); } ``` -------------------------------- ### Create Email with Representing Sender Source: https://context7.com/sicos1977/msgkit/llms.txt Create an email message that is sent on behalf of another user, typically used for delegate or shared mailbox scenarios. This involves specifying both the actual sender and the representing user. ```csharp using MsgKit; using MsgKit.Enums; // Create email sent on behalf of another user using (var email = new Email( new Sender("assistant@example.com", "Executive Assistant"), new Representing("ceo@example.com", "Chief Executive Officer"), "Quarterly Report")) { email.Recipients.AddTo("board@example.com", "Board of Directors"); email.Subject = "Q4 Quarterly Report"; email.BodyText = "Please find attached the Q4 quarterly report for your review."; email.BodyHtml = "

Please find attached the Q4 quarterly report for your review.

"; email.Importance = MessageImportance.IMPORTANCE_HIGH; email.SentOn = DateTime.UtcNow; email.Attachments.Add(@"C:\Reports\Q4-Report.xlsx"); email.Save(@"C:\Output\quarterly-report.msg"); } ``` -------------------------------- ### Set Transport Message Headers Source: https://context7.com/sicos1977/msgkit/llms.txt Configure custom email headers for threading, tracking, or compliance using raw text or the MessageHeader object. ```csharp using MsgKit; using MsgKit.Mime.Header; using (var email = new Email( new Sender("sender@example.com", "Sender"), "Email with Custom Headers")) { email.Recipients.AddTo("recipient@example.com", "Recipient"); email.BodyText = "This email includes custom transport headers."; // Set headers from raw text email.TransportMessageHeadersText = @"X-Custom-Header: CustomValue X-Tracking-Id: 12345-ABCDE X-Priority: 1 X-Mailer: MsgKit Application"; // Or create and manipulate headers programmatically email.TransportMessageHeaders = new MessageHeader(); email.TransportMessageHeaders.SetHeaderValue("X-Custom-Application", "MyApp v1.0"); email.TransportMessageHeaders.SetHeaderValue("X-Correlation-Id", Guid.NewGuid().ToString()); // Set message ID and references for email threading email.InternetMessageId = ""; email.InternetReferences = ""; email.InReplyToId = ""; email.Save(@"C:\Output\custom-headers.msg"); } ``` -------------------------------- ### Convert EML to MSG Files Source: https://context7.com/sicos1977/msgkit/llms.txt Utilize the Converter class to transform EML files into MSG format using file paths or streams. ```csharp using MsgKit; using System.IO; // Convert EML file to MSG file Converter.ConvertEmlToMsg( emlFileName: @"C:\Input\email.eml", msgFileName: @"C:\Output\email.msg"); // Convert using streams for more control using (var emlStream = new FileStream(@"C:\Input\email.eml", FileMode.Open)) using (var msgStream = new FileStream(@"C:\Output\email.msg", FileMode.Create)) { Converter.ConvertEmlToMsg(emlStream, msgStream); } // Example: Convert all EML files in a directory var emlFiles = Directory.GetFiles(@"C:\Input", "*.eml"); foreach (var emlFile in emlFiles) { var msgFile = Path.ChangeExtension(emlFile, ".msg"); msgFile = Path.Combine(@"C:\Output", Path.GetFileName(msgFile)); Converter.ConvertEmlToMsg(emlFile, msgFile); } ``` -------------------------------- ### Create a Draft Email Source: https://context7.com/sicos1977/msgkit/llms.txt Create a draft email message that will appear as unsent in Microsoft Outlook. This is achieved by setting the 'draft' parameter to true during the Email object instantiation. ```csharp using MsgKit; using MsgKit.Enums; // Create a draft email (appears as unsent in Outlook) using (var draft = new Email( new Sender("user@example.com", "User Name"), "Draft Subject", draft: true)) { draft.Recipients.AddTo("recipient@example.com", "Recipient"); draft.BodyText = "This is a draft message that can be edited in Outlook."; draft.Importance = MessageImportance.IMPORTANCE_NORMAL; draft.IconIndex = MessageIconIndex.UnsentMail; draft.Save(@"C:\Output\draft-email.msg"); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.