HTML JPG PDF XML MSG
Aspose.Email  for .NET
MSG

Bulk Report Generation in MSG Format via C#

Generate MSG email messages in bulk without requiring Outlook or Thunderbird.

How to Generate MSG based Reports Using C#

In order to create MSG reports, we’ll use

Aspose.Email for .NET

API which is a feature-rich, powerful and easy to use report generation API for C# platform. Open

NuGet

package manager, search for Aspose.Email and install. You may also use the following command from the Package Manager Console.

<h3>Package Manager Console Command</h3>

PM> Install-Package Aspose.Email

Steps to Assemble MSG via C#

  1. Create a template from MailMessage
  2. Add dynamic fields for Subject, To, From & HtmlBody fields
  3. Create a TemplateEngine using the MailMessage object
  4. Create data source and mapping to the template fields
  5. Create messages in bulk using TemplateEngine.Instantiate method
  6. Save messages in MSG format

System Requirements

Aspose.Email for .NET is supported on all major operating systems. Just make sure that you have the following prerequisites.

  • Microsoft Windows or a compatible OS with .NET Framework, .NET Core, and Xamarin Platforms
  • Development environment like Microsoft Visual Studio
  • Aspose.Email for .NET referenced in your project
 

C# example code for MSG message report generation


    // create a template from MailMessage
    MailMessage template = new MailMessage();
    // add template field to subject
    template.Subject = "Hello, #FirstName#";
    template.From = new MailAddress("This email address is being protected from spambots. You need JavaScript enabled to view it.", "This email address is being protected from spambots. You need JavaScript enabled to view it.");
    // add template field to receipt
    template.To.Add(new MailAddress("#Receipt#", true));
    // add template field to html body
    template.HtmlBody = "Dear #FirstName# #LastName# Sent Date: #Date#";
    // create a new TemplateEngine with the template message.
    var engine = new Email.Tools.Merging.TemplateEngine(template);
    
    // fill a DataTable
    var dt = new System.Data.DataTable();
    dt.Columns.Add("Receipt", typeof(string));
    dt.Columns.Add("First Name", typeof(string));
    dt.Columns.Add("Last Name", typeof(string));
    dt.Columns.Add("Date", typeof(DateTime));
    System.Data.DataRow dr;
    
    dr = dt.NewRow();
    dr["Receipt"] = "This email address is being protected from spambots. You need JavaScript enabled to view it.";
    dr["First Name"] = "Nancy";
    dr["Last Name:"] = "Davolio";
    dr["Date"] = System.DateTime.Now;
    dt.Rows.Add(dr);
    
    dr = dt.NewRow();
    dr["Receipt"] = "This email address is being protected from spambots. You need JavaScript enabled to view it.";
    dr["First Name"] = "Andrew";
    dr["Last Name"] = "Fuller";
    dr["Date"] = System.DateTime.Now;
    dt.Rows.Add(dr);
    
    dr = dt.NewRow();
    dr["Receipt"] = "This email address is being protected from spambots. You need JavaScript enabled to view it.";
    dr["First Name"] = "Janet";
    dr["Last Name"] = "Leverling";
    dr["Date"] = System.DateTime.Now;
    dt.Rows.Add(dr);
    
    // map columns
    var mappings = new System.Data.Common.DataColumnMappingCollection();
    mappings.Add(new System.Data.Common.DataColumnMapping("Receipt", "Receipt"));
    mappings.Add(new System.Data.Common.DataColumnMapping("First Name", "FirstName"));
    mappings.Add(new System.Data.Common.DataColumnMapping("Last Name", "LastName"));
    mappings.Add(new System.Data.Common.DataColumnMapping("Date", "Date"));
    Aspose.Email.MailMessageCollection messages;
    
    //  create messages from engine
    messages = engine.Instantiate(dt, mappings);
    for (int i = 0; i < messages.Count; i++)
    {
        // save messages in MSG format
        messages[i].Save(i + ".msg");
    }
 
  • About Aspose.Email for .NET API

    Aspose.Email is a Microsoft Outlook and Thunderbird formats parsing solution. One can easily create, manipulate, convert email and storage formats such as MSG, EMLX, EML and MHT. Handling of email attachments, customization of message headers and implementation of different network protocols like POP3, IMAP & SMTP to send & receive emails is much easier. Its a standalone API and does not require Microsoft Outlook or any other software installation.

    Free App to Assemble MSG

    Check our live demos to create MSG files with following benefits.

      No need to download or setup anything
      No need to write or compile code
      Just upload MSG file and hit the "Assemble" button
      Download the resultant MSG file from the link

    MSG What is MSG File Format

    MSG is a file format used by Microsoft Outlook and Exchange to store email messages, contact, appointment, or other tasks. Such messages may contain one or more email fields, with the sender, recipient, subject, date, and message body, or contact information, appointment particulars, and one or more task specifications. The properties that constitute the Message object, including are also a part of the MSG file. MSG file has headers, main message body, and hyperlinks as plain ASCII text. MSG files are also suitable with the programs that need Microsoft's Messaging Applications Programming Interface (MAPI).

    Read More

    Other Supported Report Generation Formats

    Using C#, one can easily generate reports of multiple formats including.

    EML (Outlook Email Messages)
    MBOX (Electronic Mail Messages)
    OST (Offline Storage Files)
    PST (Outlook Personal Storage Files)