PowerTCP Mail for .NET
CopyTo Method
Example 




The name of the destination mailbox.
Copy the message to another mailbox.
Syntax
Public Sub CopyTo( _
   ByVal destination As Mailbox _
) 
Dim instance As ImapMessage
Dim destination As Mailbox
 
instance.CopyTo(destination)
public void CopyTo( 
   Mailbox destination
)
public: void CopyTo( 
   Mailbox* destination
) 
public:
void CopyTo( 
   Mailbox^ destination
) 

Parameters

destination
The name of the destination mailbox.
Exceptions
ExceptionDescription
ProtocolExceptionBad IMAP protocol response received from server.
System.Net.Sockets.SocketExceptionA communications failure has occurred.
Remarks

This method copies the message to the specified mailbox with the IMAP COPY command.

Example
In this example, the Imap component copies messages that match a specified criteria to another mailbox.
private void getMessages(object state)
{
    //Configure server and account info
    imap1.Session.RemoteEndPoint = new Dart.Mail.IPEndPoint(myServer, Imap.GetDefaultPort(imap1.Session));
    imap1.Session.Username = myUsername;
    imap1.Session.Password = myPassword;

    //Connect and log into the account
    imap1.Connect();
    imap1.Authenticate();

    //Set the selected mailbox to the Inbox
    imap1.SelectedMailbox = imap1.Mailboxes["INBOX"];

    // Construct the search "SEARCH SINCE 1-Jan-2012 NOT FROM JACKSON"
    ImapSearchParameter[] criteria = new ImapSearchParameter[] 
    {
        new ImapSearchParameter(ImapCriterion.Since, "1-Jan-2012"),
        new ImapSearchParameter(ImapCriterion.Not, ""),
        new ImapSearchParameter(ImapCriterion.From, "JACKSON")
    };

    // Perform the search
    ImapMessage[] messages = imap1.SelectedMailbox.Search(criteria);

    //Copy all messages that meet the criteria to the 'Save' mailbox
    foreach (ImapMessage imapMessage in messages)
        imapMessage.CopyTo(imap1.Mailboxes["Save"]);

    //Gracefully logout
    imap1.Close();
}
Private Sub getMessages(ByVal state As Object)
    'Configure server and account info
    imap1.Session.RemoteEndPoint = New Dart.Mail.IPEndPoint(myServer, Imap.GetDefaultPort(imap1.Session))
    imap1.Session.Username = myUsername
    imap1.Session.Password = myPassword

    'Connect and log into the account
    imap1.Connect()
    imap1.Authenticate()

    'Set the selected mailbox to the Inbox
    imap1.SelectedMailbox = imap1.Mailboxes("INBOX")

    ' Construct the search "SEARCH SINCE 1-Jan-2012 NOT FROM JACKSON"
    Dim criteria() As ImapSearchParameter = { New ImapSearchParameter(ImapCriterion.Since, "1-Jan-2012"), New ImapSearchParameter(ImapCriterion.Not, ""), New ImapSearchParameter(ImapCriterion.From, "JACKSON") }

    ' Perform the search
    Dim messages() As ImapMessage = imap1.SelectedMailbox.Search(criteria)

    'Copy all messages that meet the criteria to the 'Save' mailbox
    For Each imapMessage As ImapMessage In messages
        imapMessage.CopyTo(imap1.Mailboxes("Save"))
    Next imapMessage

    'Gracefully logout
    imap1.Close()
End Sub
See Also

Reference

ImapMessage Class
ImapMessage Members


PowerTCP Mail for .NET Documentation Version 4.3
© 2018 Dart Communications. All Rights Reserved.
Send comments on this topic