This project is read-only.

Copying Messages from a folder.

Topics: Help requests
Nov 7, 2013 at 12:31 PM
I noticed that the documentation chapter regarding the Copy of Messages from a folder to another is missing.
So I have few question.

I found your CopyMessageToFolder method but I wasn't been able to use it properly. Can you provide a sample on how to use that method?

Also, is it possible to copy messages from a imap server to another? (I.e. from my gmail account to a different one)

Thank you very much,

Damiano
Nov 7, 2013 at 12:46 PM
Hi Damiano,

the method Folder.CopyMessageToFolder is obsolete, and has been replaced by Message.CopyTo. A simple sample:
/* .. Init client, authenticate .. */        
/* .. message = any message .. */ 
message.CopyTo(client.Folders.Inbox);
You can pass any folder to the CopyTo method. For moving messages, use Message.MoveTo method.

Greets,

Pavel
Marked as answer by Zandam on 11/7/2013 at 6:20 AM
Nov 7, 2013 at 1:26 PM
I have more questions, but first here's my sample method (I want to copy from secondClient to firstClient):
public bool copy()
{
    /* .. Init firstClient, authenticate .. */
    /* .. Init secondClient, authenticate .. */
    var folder = secondClient.Folders["Myfolder"];
    var messages = folder.Search();
    var newFolder = firstClient.Folders["Newfolder"];
    messages.CopyTo(newFolder);
    return true;
}
As it's not working yet, can you help me pointing out what I'm doing wrong?
Thanks again in advance!

DZ
Nov 7, 2013 at 1:43 PM
Hi Zandam,

sorry, I didn't mention it, now it is not possible to copy a message from one client to another directly. Only way is getting the EML data of the message, and then upload it using Folder.AppendMessage to another client:
/* message is a message associated with  client1 */
/* Folder is a folder associated with  client2 */
var data = message.ToEml();
folder.AppendMessage(data);
Marked as answer by Zandam on 11/7/2013 at 6:20 AM