Creating New Email Items in a Folder using C#

  • Thread starter Thread starter covot
  • Start date Start date
C

covot

I want to be able to create a new email item, set all of its properties (all
of them) and add them to a specific folder in Outlook (I am trying to add
items into Outlook that were not received via email).

I have gotten pretty far with this so far, but am running into some annoying
problems which I will describe.

So far, I have been able to create a new mail item in a specific folder like
this:

Outlook.MailItem mItem = (Outlook.MailItem)folder.Items.Add("IPM.Note");

set the body and subject and then do a:

mItem.Save();
mItem.Move(folder);

(which is weird to begin with... why create it in that folder and then have
to move it again?).

But that aside, here are my problems:

1. The above method creates a new email message as if I wanted to send it to
someone. It saves it as a draft email. However, this is not what I want. I
want it to be an email as if I had received it.

2. I want to be able to set the received date and Sender of the message. I
cannot do this, those properties are read-only.

If anyone knows how to accomplish any of the above tasks, I will be
eternally greatful.
 
Create it as an IPM.Post message rather than IPM.Note - it will be created
in the sent state; then change the MessageClass property back to IPM.Note.
You will still need to change (or delete) the PR_ICON_INDEX Extended MAPI
property to make sure the icon is right.
To set the sender, you must set a bunch of PR_SENDER_xxx and
PR_SENT_REPRESENTING_xxx properties using Extended MAPI, CDO 1.21 or
Redemption. No Outlook Object Model.
Also note that MailItem.Move is a function that returns the new item, it is
not a sub. The original item must be immediately discarded:

mItem = mItem.Move(folder);

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

Have you any recommended resources on using Extended MAPI in C# / .NET?

(off to google now)
 
Using Extended MAPI in .Net is unsupported to say the least, but there are
some wrappers available (google for mapi33).
You can access most of the Extended MAPI functionality using CDO 1.21 or
Redemption (without all the pain associated with Extended MAPI).

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

We tried to use the way you suggested, but its still coming as a compose and the issue is not solved.

Can you help us fixing this please.

Regards
Rahul Mer
 
Back
Top