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

Bulk Report Generation in OST Format via C#

Generate email messages in bulk and add to OST file via .NET API.

How to Generate OST based Reports Using C#

In order to create OST 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.

Package Manager Console Command


PM> Install-Package Aspose.Email

Steps to Assemble OST via C#

  1. Create a template as MailMessage and add dynamic fields
  2. Create data source and mapping
  3. Initialize TemplateEngine using the MailMessage object
  4. Call TemplateEngine.Instantiate method to generate messages in bulk
  5. Create a new PST with PersonalStorage.Create method
  6. Add folder in PST
  7. Add messages from TemplateEngine to folder using FolderInfo.Add method
  8. Save in OST 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 OST 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 new PST
    var pst = Email.Storage.Pst.PersonalStorage.Create("storage.pst", Email.Storage.Pst.FileFormatVersion.Unicode);
    // add folder to PST
    var inboxFolder = pst.RootFolder.AddSubFolder("Inbox");
    
    //  create messages from engine
    messages = engine.Instantiate(dt, mappings);
    for (int i = 0; i < messages.Count; i++)
    {
        // save messages in OST format
        messages[i].Save(i + ".ost");
        inboxFolder.AddMessage(MapiMessage.FromMailMessage(messages[i]));
    }
    // save in OST format
    pst.SaveAs("output.ost", Email.Storage.Pst.FileFormat.Ost);
 
  • 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 OST

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

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

    OST What is OST File Format

    OST or Offline Storage Files represent user's mailbox data in offline mode on local machine upon registration with Exchange Server using Microsoft Outlook. It is automatically created on the first use of Microsoft Outlook upon connectivity with server. Once the file is created, the data is synchronized with the email server so that it is available offline as well in case of disconnectivity from email server. OST files can user mailbox items such as emails, contacts, calendar information, notes, tasks and other similar data. Users can create emails and other data items in OST file even in the absence of connection to the server, but these will not be synchronized with the server. Once the connection is established, the local file is synchronized with the server again so that both the server and the local copy are at the same level of information.

    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)
    MSG (Outlook & Exchange Format)
    PST (Outlook Personal Storage Files)