C#.Net Outlook 2003 automation (programmatically) with Interop

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

C#.Net Outlook 2003 automation (programmatically) with
Microsoft.Office.Interop.Outlook

Problem:
I have my outlook 2003 configured with multiple mailbox on my local machine.
I want to specify the mailbox and server (Exchange server mail box)
to connect and then save the mailitems(from Inbox or any other folder)
based on a filter to a*.msg file.
I want to achieve this using only one Interop dll if this is possible.

Tried so far:
I have tried using both Outlook 11.0 object library
(Microsoft.Office.Interop.Outlook)
and Interop.MAPI dll but have not been successful to connect to a different
mailbox and save to *.msg file using only Interop.Outlook or Interop.MAPI.

Using Microsoft.Office.Interop.Outlook:
I have been able to save the defaultfolder(Inbox) to *.msg files
but I want to change the default mailbox to a second mailbox like
username2 instead of default mailbox username1.
How do I accomplish this using automation from C#.Net using
Microsoft.Office.Interop.Outlook?

Other Workaround using Interop.MAPI dll:
I have been able to connect using the Session.Logon of the interop.MAPI dll
but the mapi dll object model does not allow the messages to be saved to
*.msg file.
Any workaround using Interop.MAPI dll?

Any ideas/suggestions are welcome.

Thanks
Rob
 
CDO and Extended MAPI are not supported for use with .NET code or for usage
across the Interop.

You can log into a different Outlook profile that has the secondary mailbox
or you can load it as part of your profile or use
NameSpace.GetSharedDefaultFolder to get at that mailbox. If it's part of
your profile just iterate the Folders collection of NameSpace to find the
top of that store and walk it down to get to the secondary mailbox. Using
GetSharedDefaultFolder you create a Recipient object of an alias that has
permissions to log into that mailbox and specify to load the Inbox folder.

From those points you just save the items as MSG as usual.
 
Ken,

Thanks for the suggestion.

Do you have a sample to create a recipient object that
uses GetSharedDefaultFolder in c#?

I have two mailboxes set in outlook
1) Mailbox - username1 -- default mailbox
2) Mailbox - username2

I should create a recipient object that points to Mailbox - username2
and lets assume an userid username2 and password of 'password'.

I should point to Mailbox - username2 and loop through the folders
collection to get to inbox and save the email messages to a *.msg file.

Thanks
Rob
 
If the email address for mailbox 2 is "(e-mail address removed)" then it would go
something like this in C#.

// app == Outlook.Application, ns == NameSpace
Outlook.Recipient recip =
(Outlook.Recipient)ns.CreateRecipient("(e-mail address removed)");
recip.Resolve;

Outlook.MAPIFolder folder = (Outlook.Folder)ns.GetSharedDefaultFolder(recip,
Outlook.OlDefaultFolders.olFolderInbox);

or you can get the ns.Folders collection and look for one with a caption of
"Mailbox - User 2" and from there get that Folder's Folders collection and
look for one named "Inbox".
 
Back
Top