views:

1040

answers:

7

I am working on an application where i need to transfer mails from a mailbox to anoter one.I can not send these mails using smtp because this willchange the header information .I am using C# and out look api to process mails . is thre any way i can transfer mails to other mail box without changing mail header.

A: 

If you use the Outloook API I'm sure there is support for backup and restore. So backup your mails from one account and restore it on the other. This would be my first try. PS: I'm not familiar with the API.

Drejc
A: 

What's the relationship of the mailboxes? Are they on the same Exchange server? If so, your best bet is to use MAPI to copy the messages. If not, you can either export the messages to a PST or to a collection of .msg files. Does this need to be automated?

Cain T S Random
A: 

What exactly do you mean by "transfer"? If you're talking about the equivalent of drag and dropping a mail from one mailbox to another loaded inside the same Outlook profile, then just use the MailItem.Move method.

Oliver Giesen
A: 

By Transfer I mean, I need to take a mail from one mail box and move this to another mailbox without changing any header information. If I use smtp , header information will be changed. I have heared that using MAPI mail can be moved from one mail box to another mail box. any pointers.

Kapilg
Yes, that's what you wrote before already. We need to know more about the two mailboxes you wish to transfer the items between: Are they on the same Exchange Server? Are they maybe even loaded into the same Outlook profile (via the Additional Mailbox option)? In the latter case, see my answer.
Oliver Giesen
BTW: This is not an answer to your question. You should respond to comments or counter-questions either via another comment or by adding information to your original question.
Oliver Giesen
The Mail boxes are on the same exchange server but they can not be loaded in the same out look profile because i have to move the nmails from 40000 mail boxes to this one mail box so it wont be possible to load the this mail box on each profile .
Kapilg
OK, that makes the task much clearer. Can you add that information to your question?
Oliver Giesen
A: 

Then what you need is MAPI. It's a pretty complicated API. There's one, long-out-of-print book about it, but that's it. The best place to start is to download MFCMapi and look at how you might do what you need to, e.g. open two users' mailboxes and copy a message between them. Then, look at the source for MFCMapi and see how it's done, and work from there.

Cain T S Random
+1  A: 

If you cannot load all relevant mailboxes into a single Outlook profile, then this cannot be solved using the Outlook API. It should however be possible to run a standalone application from an administrative account that accesses the Exchange information store directly via Extended MAPI. You can then open the source mailboxes sequentially and move the relevant mail items to the target mailbox.

This would allow you to run a batch job harvesting all mailboxes from a central location in a single giant operation. If however your task is to move messages as they appear then maybe addressing this in a more decentralized fashion via Outlook addins installed on the source machines might be a more sensible approach after all. Maybe if you told us a little bit more about your motivation for moving those items we can come up with an even better solution.

If you go for the centralized harvester approach I strongly recommend using a helper library like Redemption for this though as otherwise it will probably take a couple of months before you have gathered enough knowledge to address the task. The RDO framework (Redemption Data Objects) should be especially well suited to get you running ASAP.

Oliver Giesen
+1  A: 

I was able to move the mails from one mail box to another using Redemption. This is like a copy mail from one mail box to another. First logon to the destination mail box using redemption.Get the referenceto the folder where you want to move the mail . In my case , it was inbox. now convert the outlook mail item to RDOMail and copy the rdomail to destination folder. here the is code -

rdoSession.LogonExchangeMailbox("TEST", "ServerName"); RDOExchangeMailboxStore mailBoxStore = (Redemption.RDOExchangeMailboxStore) rdoSession.Stores.DefaultStore;

            RDOFolder inboxFolder = null;

            foreach (RDOFolder rdoFolder in mailBoxStore.IPMRootFolder.Folders)
            {
                if (rdoFolder.Name.Equals("Inbox", StringComparison.InvariantCultureIgnoreCase))
                {
                    inboxFolder = rdoFolder;
                    break;
                }
            }
            rdoMail.CopyTo(inboxFolder);

with this, mail will be copied to the new mail box without changing any header information.

Kapilg
Sounds like you accepted my answer then, no?
Oliver Giesen