Create PST file

M

MA

Hi,

I will like to write a C# utility to create PST file from other email
applications. I would like to get your suggestions about the API's to
use, sample code or any reference URLs.

Thanks in advance.

Regards,
MA
 
M

MA

Thanks for your suggestions.

In order to create the PST, I need to re-constitute a Outlook message
from another client. Can I use the Outlook Object Model to perform the
task?

Can I create the message with embedded message in Outlook and preserve
the Date, sender information, attachments, etc?

Regards,
MA
 
D

Dmitry Streblechenko

Do you mean you need to copy a mesage to the new PST store?
Call AddStore, find in the newly added root folder in the Namespace.Folders
collection, create the target folder there (MAPIFolder.Folders.Add), then
call OldMailItem.Copy (returns teh new MailItem object), then move it to the
target folder using NewMailItem.Move(NewFolder).

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
M

MA

Sorry for not explaining clearly.

I would like to write a utility which lets you to create a PST file
from another client (e.g. GroupWise, Lotus). Its not going to be copy
because the message will be different format.

I would need to create the message in Outlook and preserve the
original information (date time stamp, sender etc) then finally add to
the target folder.

I prefer to write in C#, my initial questions are:

1) Should I follow the Outlook object model, Extended MAPI, etc?

2) I need to re-constitute the message in Outlook, some message may
have the attached message, etc. Is there any known limitation with the
suggested API in Q1?

3) Any resources available which may provide useful information.


Thanks again for answering my questions.

Regards,
MA
 
D

Dmitry Streblechenko

So you need to create a new PST file on a machine where Outlook is installed
and populate it with the messages created and populated explicitly by your
code, right?
OOM won't work too well - firstly, it tends to create regular mail items in
the default Drafts folder, even if you explcilty specify a different folder
(MAPIFolder.Items.Add).
Secondly, it does not allow to create regular message in the sent state. You
can create a post item and then change the message class, but thee icon will
be wrong.
Thirdly, it does not provide access to the MAPI properties not exposed
thrugh the Outlook Object (Outlook 2007 with the PropertyAccessor object is
the only exception) - e.g. you cannot set the the sender (you need to set 5
or 6 MAPI properties).

Extended MAPI would be my preferable solution, but it is not supported by MS
in the .Net environment (you can still use a third party library such as
MAPI33), but if you have never done MAPI, the learning curve is extermely
steep.

<plug>
You can also use Redemption (URL below) - see RDOSession.AddPstStore etc.
You will be eablee to set the sent/unsent property (RDOMail.Sent, settable
before tehe first call to Save), you can also set any MAPI propetty using
RDOMail.Fields[]
</plug>


Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
M

MA

Thanks Dmitry for your details explanation.
So you need to create a new PST file on a machine where Outlook is installed
and populate it with the messages created and populated explicitly by your
code, right?

Yes. Conversion utility will have to create a new PST file will be
have messages (sent, received, posted, draft), folders, etc. Similar
to the master email client. Rules and other options is not a high
priority for the initial conversion.

Based on your suggestions, it appear the MAPI33 and Redemption is the
ONLY option to write the utility in .NET environment. My next question
is, which library (MAPI33 or Redemption) to use for some basic purpose
below:

- Create Outlook messages and preserve original information (e.g.
sender name, create date, received date, attachments, etc)
- Messages need to be placed to the target folder
- Message may contains attached messages
- Preserve message status (received, sent, post, draft)
- Different message type (email, note, appointment, task)


Thanks again for your suggestions.

Regards,
MA
 
D

Dmitry Streblechenko

Both Redemption and MAPI33 will do that, but MAPI33 is a essentially a .Net
MAPI header, while Redemption tries to hide all the gory MAPI details and
has the object model (RDO family of objects) similar to the Outlook Object
Model or CDO 1.21.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
M

MA

Thanks again for your help.

In the conversion process, I have to create received, sent, draft,
posted messages. Does the Redemption or MAPI33 library lets you to
create sent messages without actually sending the messages?

For example, I have to re-constitute the sent message from the other
client to Outlook. Obviously I do not want to send the message, just
create the message as sent type.

Which library (Redemption or MAPI33) you recommend to perform this
task and also easy to use?

Do you have any advise regarding the Visual Studio 2005 Tools for
Microsoft Office? I am using the VS 2003 and planning to upgrade to VS
2005 soon. Any limitation on VS 2003 to use the Redemption or MAPI33?

Sorry for asking many questions as I am trying to gather advice from
expert to save time and efforts :)

Thanks,
MA
 
D

Dmitry Streblechenko

Yes, you can create a message in the sent state if you remove MSGFLAG_UNSENT
bit from the PR_MESSAGE_FLAGS before saving the message for the very first
time (MAPI limitation).
If you are comfortable with Extended MAPI and you do not mind dealing with
all of its compexity, MAPI 33 is the way to go. Otherwise Redemption would
probably be a good choice.

The script below (VB) will create a message in the sent state in the Sent
Items folder

set Session = CreateObject("Redemption.RDOSession")
Session.Logon
set NewMsg =
Session.GetDefaultFolder(olFolderSentMail).Items.Add("IPM.Note")
NewMsg.Sent = true
NewMsg.Subject = "fake sent item"
NewMsg.Body = "test body"
set Recip = NewMsg.Recipients.Add("(e-mail address removed)")
Recip.Resolve
NewMsg.Sender = Session.CurrentUser
NewMsg.SentOnBehalfOf = Session.CurrentUser
NewMsg.SentOn = Now
NewMsg.ReceivedTime = Now
NewMsg.Save




Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top