Regarding pst file

If i have a mail object and i want to add that mail object into my pst file.how can i add it by assigning property by property or directly i can add that mail object into my pst file.


Please reply soon

Hi Pooja,

You don’t need to add the mail object property by property. Please use the following code sample to create a MapiMessage object from MailMessage and add it to the Inbox folder of a PST. Let us know if we can be of any additional help to you.

Code Sample:

MailMessage mailMessage = MailMessage.Load("Source.msg");
MapiMessage mapi = MapiMessage.FromMailMessage(mailMessage);
PersonalStorage pst = PersonalStorage.FromFile("SourcePst.pst");
pst.GetPredefinedFolder(StandardIpmFolder.Inbox).AddMessage(mapi);
pst.Dispose();

Hi Kashif,
According to your code snippest, MailMessage.load() takes eml or msg file.If i dont have eml or msg
but i have a object who has a Mail properties. so,what should i do for creating mail in pst file.


Hi Pooja,


Could you please elaborate what do you man by “object that has Mail Properties”?

Both the MailMessage and MapiMessage provide methods for loading mail objects from stream. So, if you have a MailMessage or MapiMessage object, you can save it to stream and then add these to PST by loading them from the stream. You can have a look at these methods to know more about them:

  • MailMessage.Load(Stream);
  • MapiMessage.FromStream(stream);

Hi Kashif,

I have a query that if i want to avoid duplicate mails in pst.So is there any way to filter or avoid duplicate mails.
Hi Pooja,

At present, I couldn't find any such information that could be helpful in directly identifying duplicate entries in a PST. Each message in a PST, when added to PST, has an ENTRYID that is different for each message (despite the contents and other fields of the message are same) and are identified uniquely by this EntryID. You may try different properties like PR_CREATION_TIME, PR_LAST_MODIFICATION_TIME, PR_SUBJECT_W etc. for identifying duplicate messages.