Olm file convert to Pst

Dear suupport,

I am read the olm file without using API . it is possible to convert in pst file using Aspose.Email for .Net API.

@priyankur.chauhan,

Could you please share how you are reading the file with out using Aspose.Email API? In this case, you can read the emails one by one from it and add as messages to new PST using Aspose.Email API.

I am reading olm file every field one by one. The every field data store in diffrent data member such as subject in subject data member and To in to data member, msgbody in msgbody data member, Cc in to cc data member and attachment in attachment data member. i have a structure for every field with every field data member.which structure is fill one by one of every field with every field data member. how to add these fields in the conversion pst file.

@priyankur.chauhan,

You may please give a try to the following sample code and share the feedback.

public static void Test()
{
    DataTable table = GetTable();
    File.Delete("output.pst");
    PersonalStorage pst = PersonalStorage.Create("output.pst", FileFormatVersion.Unicode);
    FolderInfo info = pst.CreatePredefinedFolder("Inbox", StandardIpmFolder.Inbox);
    for (int i = 0; i < table.Rows.Count; i++)
    {
        MapiMessage mapi = new MapiMessage(
            "from@gmail.com", 
            table.Rows[i]["To"].ToString(),
            table.Rows[i]["Subject"].ToString(),
            table.Rows[i]["MsgBody"].ToString()
            );
        mapi.Recipients.Add(table.Rows[i]["CCAddress"].ToString(), table.Rows[i]["CCDisplayName"].ToString(), MapiRecipientType.MAPI_CC);
        mapi.Attachments.Add(table.Rows[i]["AttachmentName"].ToString(), table.Rows[i]["AttachmentData"] as Byte[]);
        info.AddMessage(mapi);
    }
    pst.Dispose();
}
public static DataTable GetTable()
{
    DataTable table = new DataTable();
    table.Columns.Add("Subject", typeof(string));
    table.Columns.Add("To", typeof(string));
    table.Columns.Add("MsgBody", typeof(string));
    table.Columns.Add("CCDisplayName", typeof(string));
    table.Columns.Add("CCAddress", typeof(string));
    table.Columns.Add("AttachmentName", typeof(string));
    table.Columns.Add("AttachmentData", typeof(Byte[]));

    // Here we add five DataRows.
    table.Rows.Add("Subject 1", "to1@gmail.com", "Message Body 1", "CC1", "CC1@gmail.com", "att1.txt", Encoding.ASCII.GetBytes("Data in att1 file"));
    table.Rows.Add("Subject 2", "to2@gmail.com", "Message Body 2", "CC2", "CC2@gmail.com", "att2.txt", Encoding.ASCII.GetBytes("Data in att2 file"));
    table.Rows.Add("Subject 3", "to3@gmail.com", "Message Body 3", "CC3", "CC3@gmail.com", "att3.txt", Encoding.ASCII.GetBytes("Data in att3 file"));
    table.Rows.Add("Subject 4", "to4@gmail.com", "Message Body 4", "CC4", "CC4@gmail.com", "att4.txt", Encoding.ASCII.GetBytes("Data in att4 file"));
    table.Rows.Add("Subject 5", "to5@gmail.com", "Message Body 5", "CC5", "CC5@gmail.com", "att5.txt", Encoding.ASCII.GetBytes("Data in att5 file"));
    return table;
}

Dear Support,

I am using your given sample code but the attachment data is not properly write in pst file.when i import the created pst file in Microsoft Office Outlook 2016 and click the attachment then show a message the file “image003[6].jpg” could not be opened.It may be damaged or use a file format that Preview doesn’t recognize.

@priyankur.chauhan,

I have modified the above sample code such that fifth message contains an attachment which is image. After this modification, the output PST file is opened in Outlook 365. This particular message is opened and attachment is viewed. It is observed that image opens fine and no issue is observed. Please give it a try and share the feedback.

table.Rows.Add("Subject 5", "to5@gmail.com", "Message Body 5", "CC5", "CC5@gmail.com", "Capture.png", File.ReadAllBytes(@"Capture.png"));

Dear Support,

I want to know how to add multiple attachment data in a single Column with a single row. how is possible the multiple attachment is write in a single mail. how to add multiple attachment in single data row. i do not create multiple Column for multiple attachment(only single attachment data Column with multiple attachment). your given sample code has five DataRows which has five different mail in converted pst but i want multiple attachment in single datarow with 7 Column in given sample code how is possible.

@priyankur.chauhan,

This is quite possible to combine multiple attachments into one byte array and then save into single column of a row. When this same byte array is read from database or any other source, it needs to be converted to the multiple attachments again using same programming logic with which it was combined. For this Aspose.Email cannot itself extract multiple attachments from a byte array as it does not know the logic like how much attachments are there, what are their names and sizes etc.

You need to extract multiple attachments at your own using your logic from the source byte array and then add those attachments to the mail message.

Other option is to save whole byte array into one file and then attach that single file with the mail message. However on receiving end, when this attachment is downloaded, it shall be converted to multiple attachments using your programming logic. Similarly you can also fetch attachments from byte array and then zip them into one file for attaching them with mail message.

Please feel free to write us back if you have any other query in this regard.

Screen Shot 2018-06-04 at 2.54.37 PM.png (35.8 KB)

Dear Support,

I am using your given sample code but the html Message Body is not correctly display when i import the created pst. how is possible to display the correct plain text body and html body. the screenshort is attached with html body not display correctly.

@priyankur.chauhan,

You may please give a try to the following sample code and share the feedback.

static void Test()
{
    DataTable table = GetTable();
    File.Delete("output.pst");
    PersonalStorage pst = PersonalStorage.Create("output.pst", FileFormatVersion.Unicode);
    FolderInfo info = pst.CreatePredefinedFolder("Inbox", StandardIpmFolder.Inbox);
    for (int i = 0; i < table.Rows.Count; i++)
    {
        MapiMessage mapi = new MapiMessage(
            "from@gmail.com",
            table.Rows[i]["To"].ToString(),
            table.Rows[i]["Subject"].ToString(),
            table.Rows[i]["MsgBody"].ToString()
            );
        mapi.SetBodyContent(table.Rows[i]["MsgBody"].ToString(),BodyContentType.Html);
        mapi.Recipients.Add(table.Rows[i]["CCAddress"].ToString(), table.Rows[i]["CCDisplayName"].ToString(), MapiRecipientType.MAPI_CC);
        mapi.Attachments.Add(table.Rows[i]["AttachmentName"].ToString(), table.Rows[i]["AttachmentData"] as Byte[]);
        info.AddMessage(mapi);
    }
    pst.Dispose();

}

public static DataTable GetTable()
{
    DataTable table = new DataTable();
    table.Columns.Add("Subject", typeof(string));
    table.Columns.Add("To", typeof(string));
    table.Columns.Add("MsgBody", typeof(string));
    table.Columns.Add("CCDisplayName", typeof(string));
    table.Columns.Add("CCAddress", typeof(string));
    table.Columns.Add("AttachmentName", typeof(string));
    table.Columns.Add("AttachmentData", typeof(Byte[]));
    string htmlBody = "<!DOCTYPE html><html><head><title> Page Title </title></head><body><h1>This is a Heading</h1><p> This is a paragraph.</p></body></html>";
    // Here we add five DataRows.
    table.Rows.Add("Subject 1", "to1@gmail.com", htmlBody, "CC1", "CC1@gmail.com", "att1.txt", Encoding.ASCII.GetBytes("Data in att1 file"));
    return table;
}

Dear Support,

Your given sample code line
mapi.SetBodyContent(table.Rows[i][“MsgBody”].ToString(),BodyContentType.Html);
give the System.NotSupportedException has been thrown Encoding 1251 data could not be found. Make sure you have correct international codeset assembly installed and enabled tell me how to solve this Exception.

@priyankur.chauhan,

I am afraid that this issue is not re-produced here. You may please give a try to the attached project on some other system as well. Also if we google this issue, we get some hints like this. Please give it a try and share the feedback.

TestProject.zip (2.6 MB)

Dear Support,

Your given TestProject.zip is working correctly write the correct html body. how is possible i implement these project sample code in own sample code what kind of package is include in the project. i also include the Aspose.Email(Aspose.Email for .Net) package but the project give exception System.NotSupportedException has been thrown Encoding 1251 data could not be found. Make sure you have correct international codeset assembly installed and enabled how to solve it.

my sample code is give System.NotSupportedException

namespace TestRef
{
static class MainClass
{
static void Main(string[] args)
{
Email_175533();
NSApplication.Init();
NSApplication.Main(args);
}
static void Email_175533()
{
PersonalStorage pst = PersonalStorage.Create("/private/var/root/Desktop/New/Output.pst", FileFormatVersion.Unicode);
FolderInfo folderInfo = pst.CreatePredefinedFolder(“Inbox”, StandardIpmFolder.Inbox);
MapiMessage mapi = new MapiMessage("from@gmail.com", "to@gmail.com", “Test Subject”, “Test Body”);
string htmlBody = “< ! DOCTYPE html>Page Title < h1> This is a Heading< /h1>< p> This is a paragraph. < /p>< /body>< /html>”;
mapi.SetBodyContent(htmlBody, BodyContentType.Html);
folderInfo.AddMessage(mapi);
}
}
}

i add a package Aspose.Email(Aspose.Email for .Net) then by default Aspose.Email.macOS.Xamarin is add but i want add Aspose.Email package. because Aspose.Email package is add in your TestProject.zip sample code. how to add Aspose.Email package.

@priyankur.chauhan ,

Could you please send us your complete project (which throws this exceprion) having above mentioned code only for our testing here?

MySampleCode.zip (3.1 MB)
Dear Support,

Kindly collect attached file MySampleCode.zip.
Main.cs file store the sample code line
mapi.SetBodyContent(htmlBody, BodyContentType.Html);
generate the System.NotSupportedException.if i am using
mapi.SetBodyContent(htmlBody, BodyContentType.PlainText); then exception not generated but the html body does not show correct preview.

@priyankur.chauhan,

I an afraid that I am not able to load this project into my Visual Studio 2015 IDE. It seems that this is not standard Windows Console Application, therefore it is requested that you may create fresh project which is windows based console application. Then add the reference to Aspose.Email using NuGet Package Manager and share the project with us. It will help us to observe the problem and provide assistance accordingly.

Dear Support,

The Project MySampleCode.zip is created in mac os Visual Studio this is not standard Windows Console Application, because i am mac os developer and the Aspose.Email for .Net API also used for mac os and i also add the reference to Aspose.Email using NuGet Package Manager with MySampleCode.zip project.
only this line
mapi.SetBodyContent(htmlBody, BodyContentType.Html);
generate the exception.when i used BodyContentType.Html function.
how to resolve this problem.

When i add the reference to Aspose.Email using NuGet Package Manager with your given sample code TestProject.zip by default Aspose.Email.dll is created but When i add the reference to Aspose.Email using NuGet Package Manager with own created MySampleCode.zip then Aspose.Email.macOS.Xamarin.dll is created. i add the same reference to Aspose.Email using NuGet Package Manager from both project but both project create different .dll file such as(TestProject.zip is Aspose.Email.dll and MySampleCode.zip is Aspose.Email.macOS.Xamarin.dll).

How is possible to resolve exception in mac os visual studio sample project using Aspose.Email for .Net API.MySampleCode.zip (3.1 MB)

@priyankur.chauhan,

I have installed Visual Studio for mac and created new console based application. Then Aspose.Email package is added to this project. Everything is working fine and above mentioned code runs without any error. You may please download complete project from this link and give it a try.

How to create new console based application in mac os and Aspose.Email package is added to this project tell me step by step.because i want to know how to create Aspose.Email.dll default in FirstMacProject/FirstMacProject/bin/Debug/Aspose.Email.dll path but in MySampleCode create Aspose.Email.macOS.Xamarin.dll default in MySampleCode/bin/Debug/Aspose.Email.macOS.Xamarin.dll path.
how is possible to solve this problem.

@priyankur.chauhan,

Here a video and snapshots are attached showing the creation of a new project in Visual Studio for MAC and then adding the Aspose.Email package. Please refer it for creating new project and adding the Aspose.Email functionality and share the feedback. You may please download the video from this link.

Screen Shot 2018-06-12 at 7.12.55 PM.jpg (247.8 KB)
Screen Shot 2018-06-12 at 8.20.42 PM.jpg (210.3 KB)