Working with MapiJournal in PST

Adding MapiJournal to PST

The Create a New PST File and Add Subfolders article shows how to create a PST file and add a subfolder to it. With Aspose.Email you can add MapiJournal to the Journal subfolder of a PST file that you have created or loaded. Below are the steps to add MapiJournal to a PST:

  1. Create a MapiJournal object
  2. Set the MapiJournal properties using a constructor and methods.
  3. Create a PST using the PersonalStorage.Create() method.
  4. Create a pre-defined folder (Journals) at the root of the PST file by accessing the root folder and then calling the AddMapiMessageItem() method.

The following code snippet shows you how to create a MapiJournal and then add it to the journal folder of a newly created PST file.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET
string dataDir = RunExamples.GetDataDir_Outlook();
MapiJournal journal = new MapiJournal("daily record", "called out in the dark", "Phone call", "Phone call");
journal.StartTime = DateTime.Now;
journal.EndTime = journal.StartTime.AddHours(1);
string path = dataDir + "CreateNewMapiJournalAndAddToSubfolder_out.pst";
if (File.Exists(path))
{
File.Delete(path);
}
using (PersonalStorage personalStorage = PersonalStorage.Create(dataDir + "CreateNewMapiJournalAndAddToSubfolder_out.pst", FileFormatVersion.Unicode))
{
FolderInfo journalFolder = personalStorage.CreatePredefinedFolder("Journal", StandardIpmFolder.Journal);
journalFolder.AddMapiMessageItem(journal);
}

Adding Attachments to MapiJournal

The following code snippet shows you how to add attachments to MapiJournal.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET
string dataDir = RunExamples.GetDataDir_Outlook();
string[] attachFileNames = new string[] { dataDir + "Desert.jpg", dataDir + "download.png" };
MapiJournal journal = new MapiJournal("testJournal", "This is a test journal", "Phone call", "Phone call");
journal.StartTime = DateTime.Now;
journal.EndTime = journal.StartTime.AddHours(1);
journal.Companies = new string[] { "company 1", "company 2", "company 3" };
foreach (string attach in attachFileNames)
{
journal.Attachments.Add(attach,File.ReadAllBytes(attach));
}
journal.Save(dataDir + "AddAttachmentsToMapiJournal_out.msg");