Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Interop / February 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
rob - 13 Feb 2007 18:09 GMT
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
Ken Slovak - [MVP - Outlook] - 13 Feb 2007 20:11 GMT
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.

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm

> C#.Net Outlook 2003 automation (programmatically) with
> Microsoft.Office.Interop.Outlook
[quoted text clipped - 32 lines]
> Thanks
> Rob
rob - 13 Feb 2007 20:52 GMT
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

> C#.Net Outlook 2003 automation (programmatically) with
> Microsoft.Office.Interop.Outlook
[quoted text clipped - 29 lines]
> Thanks
> Rob
Ken Slovak - [MVP - Outlook] - 13 Feb 2007 21:36 GMT
If the email address for mailbox 2 is "user2@mydomain.com" then it would go
something like this in C#.

// app == Outlook.Application, ns == NameSpace
Outlook.Recipient recip =
(Outlook.Recipient)ns.CreateRecipient("user2@mydomain.com");
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".

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm

> Ken,
>
[quoted text clipped - 15 lines]
> Thanks
> Rob
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.