To move one or more messages in the current working mailbox to another mailbox, simply call the MoveMessage method. If you are going to move a single message, you can either pass message sequence number of unique id and the destination mailbox name to the method. If you wish to move more than one messages, create a new instance of the message id list class - ImapMessageIdCollection and add sequence numbers or unique ids of the messages you want to move.
The following steps will help you to do that:
Moving message(s)
- Add using directives to your code to create aliases for existing namespaces and avoid having to type the fully qualified type names. The code looks similar to the following:
using ComponentPro.Net;
using ComponentPro.Net.Mail;
Imports ComponentPro.Net
Imports ComponentPro.Net.Mail
- Create a new instance of the Imap class.
- Now you can connect to the IMAP server with Connect methods. The code looks similar to the following:
// IMAP server information.
const string serverName = "myserver";
const string user = "name@domain.com";
const string password = "mytestpassword";
const int port = 993;
const SslSecurityMode securityMode = SslSecurityMode.Implicit;
// Create a new instance of the Imap class.
Imap client = new Imap();
// Connect to the server.
client.Connect(serverName, port, securityMode);
' IMAP server information.
Const serverName As String = "myserver"
Const user As String = "name@domain.com"
Const password As String = "mytestpassword"
Const port As Integer = 993
Const securityMode As SslSecurityMode = SslSecurityMode.Implicit
' Create a new instance of the Imap class.
Dim client As New Imap()
' Connect to the server.
client.Connect(serverName, port, securityMode)
- Use your user name and password to login with Authenticate methods. The code looks similar to the following:
// Login to the server.
client.Authenticate(user, password);
' Login to the server.
client.Authenticate(user, password)
- Now pass the message sequence id and destination mailbox name to the MoveMessage method. The code looks similar to the following:
// Select 'INBOX' mailbox.
client.Select("INBOX");
// Move a message with sequence # 1 to 'my mailbox' folder.
client.MoveMessage(1, "my mailbox");
' Select 'INBOX' mailbox.
client.Select("INBOX")
' Move a message with sequence # 1 to 'my mailbox' folder.
client.MoveMessage(1, "my mailbox")
- After completing your work, call the Disconnect method to close the IMAP session.
Final example code
using ComponentPro.Net;
using ComponentPro.Net.Mail;
...
// IMAP server information.
const string serverName = "myserver";
const string user = "name@domain.com";
const string password = "mytestpassword";
const int port = 993;
const SslSecurityMode securityMode = SslSecurityMode.Implicit;
// Create a new instance of the Imap class.
Imap client = new Imap();
// Connect to the server.
client.Connect(serverName, port, securityMode);
// Login to the server.
client.Authenticate(user, password);
// Select 'INBOX' mailbox.
client.Select("INBOX");
// Move a message with sequence # 1 to 'my mailbox' folder.
client.MoveMessage(1, "my mailbox");
// Close the connection.
client.Disconnect();
Imports ComponentPro.Net
Imports ComponentPro.Net.Mail
...
' IMAP server information.
Const serverName As String = "myserver"
Const user As String = "name@domain.com"
Const password As String = "mytestpassword"
Const port As Integer = 993
Const securityMode As SslSecurityMode = SslSecurityMode.Implicit
' Create a new instance of the Imap class.
Dim client As New Imap()
' Connect to the server.
client.Connect(serverName, port, securityMode)
' Login to the server.
client.Authenticate(user, password)
' Select 'INBOX' mailbox.
client.Select("INBOX")
' Move a message with sequence # 1 to 'my mailbox' folder.
client.MoveMessage(1, "my mailbox")
' Close the connection.
client.Disconnect()