Search code examples
emailc#-4.0outlookmove

AE.net.Mail, How to move mail to a new folder in outlook


How to move mail to a new folder in outlook?

My code:

using (ImapClient ic = new ImapClient(
                             imapAddr, 
                             myEmailID, 
                             myPasswd, 
                             ImapClient.AuthMethods.Login, 
                             portNo, 
                             secureConn)) 
{ 
     ic.SelectMailbox("INBOX"); 
     bool headersOnly = false; 
     Lazy<MailMessage>[] messages = ic.SearchMessages(SearchCondition.Unseen(), headersOnly);
     foreach (Lazy<MailMessage> message in messages) 
     { 
       MailMessage m = message.Value; 
     }
}

I try Google it but I can not find it . Any suggestions are highly appreciated.


Solution

  • to move a message to another folder do this:

    ic.MoveMessage(message.Uid, "some existing folder");
    

    The uid is the unique identifiier for the mailmessage. I assume it maps to the message-id as described in RFC for Internet Message Format. Or otherwise to the UNIQUEID in the IMAP protocol.

    to create a new folder use the this method:

    ic.CreateMailbox("new mailbox name");
    

    To send emails use an SmtpClient, like the one that is supplied in the .net framework:

            using(SmtpClient client = new SmtpClient("your smtp server.com"))
            {
                client.Send("[email protected]", 
                            "[email protected]",
                            "subject",
                            "Hello World");
            }