PowerTCP Mail for .NET
Login(String,String,String) Method
See Also  Example Send comments on this topic.
Dart.PowerTCP.Mail Namespace > Imap Class > Login Method : Login(String,String,String) Method




server
The hostname or dot address of the IMAP server.
username
The account username.
password
The account password.
Logs into an IMAP server at a specified port using a username and password.Logs into an IMAP server using a username and password.

Syntax

Visual Basic (Declaration) 
Public Overloads Function Login( _
   ByVal server As String, _
   ByVal username As String, _
   ByVal password As String _
) As ImapResponse
Visual Basic (Usage)Copy Code
Dim instance As Imap
Dim server As String
Dim username As String
Dim password As String
Dim value As ImapResponse
 
value = instance.Login(server, username, password)
C# 
public ImapResponse Login( 
   string server,
   string username,
   string password
)
Managed Extensions for C++ 
public: ImapResponse* Login( 
   string* server,
   string* username,
   string* password
) 
C++/CLI 
public:
ImapResponse^ Login( 
   String^ server,
   String^ username,
   String^ password
) 

Parameters

server
The hostname or dot address of the IMAP server.
username
The account username.
password
The account password.

Return Value

An ImapResponse object representing the response from the server.An ImapResponse object representing the response from the server.

Exceptions

ExceptionDescription
Dart.PowerTCP.Mail.ProtocolExceptionBad IMAP protocol response received from server.
System.Net.Sockets.SocketExceptionThe requested address is not valid in its context.
Dart.PowerTCP.Mail.ProtocolExceptionBad IMAP protocol response received from server.
System.Net.Sockets.SocketExceptionThe requested address is not valid in its context.

Example

The following example demonstrates logging into an IMAP server, copying read messages to a Deleted mailbox, and deleting them.
Visual BasicCopy Code
Private Sub DoMove()
   ' Demonstrate moving Read messages from "INBOX" to a "Deleted Items" box
   Try
      ' Do synchronous login with AutoList
      Imap1.Login("myServer", "myAccount", "myPassword")

      ' Create Mailbox objects for easier reference
      Dim InboxBox As Mailbox = Imap1.CurrentMailbox ' After Login with AutoList, this will be "INBOX"
      Dim DeletedBox As Mailbox = Imap1.Mailboxes("Deleted Items")

      ' Update Messages Count in "Deleted Items" box
      DeletedBox.Refresh()

      ' Display Messages Count in both boxes
      LabelDisplay.Text = InboxBox.Messages.Count.ToString() + "  " + DeletedBox.Messages.Count.ToString()

      ' Get an array of ImapMessages with just flags
      Dim Messages As ImapMessage() = InboxBox.Get(InboxBox.Messages(0), InboxBox.Messages(InboxBox.Messages.Count-1), ImapMessageSections.Flags)

      ' Copy Read Messages to "Deleted Items" box and Mark them for Deletion
      Dim Msg as ImapMessage
      For Each Msg in Messages
        If Msg.Seen Then 'If Seen flag is set 
           Msg.CopyTo(DeletedBox) ' Copy to "Deleted Items" box
           Msg.Delete = True ' Set deleted flag in "INBOX"
        End If
      Next

      'Permanently Remove Copied Messages from "INBOX"
      InboxBox.Purge()

      'Update Messages Count in "Deleted Items"
      DeletedBox.Refresh()

      'Display new Messages Counts
      LabelDisplay.Text = InboxBox.Messages.Count.ToString() + "  " + DeletedBox.Messages.Count.ToString()

      'Logout from server
      Imap1.Logout()
   
   Catch Ex As Exception
       ' Show MessageBox if error occurs
       MessageBox.Show(Ex.Message, "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
   End Try
End Sub
C#Copy Code
private void DoMove()
{
   //Demonstrate moving Read messages from "INBOX" to a "Deleted Items" box
   try
   {
      //Do synchronous login with AutoList
      imap1.Login("myServer", "myAccount", "myPassword");

      //Create Mailbox objects for easier reference
     Mailbox inboxBox = imap1.CurrentMailbox; //After Login with AutoList, this will be "INBOX"
     Mailbox deletedBox = imap1.Mailboxes["Deleted Items"];

     //Update Messages Count in "Deleted Items" box
     deletedBox.Refresh();

     //Display Messages Count in both boxes
     labelDisplay.Text = inboxBox.Messages.Count.ToString() + "  " + deletedBox.Messages.Count.ToString();

     //Get an array of ImapMessages with just flags
     ImapMessage[] messages = inboxBox.Get(inboxBox.Messages[0], inboxBox.Messages[inboxBox.Messages.Count-1], ImapMessageSections.Flags);

     //Copy Read Messages to "Deleted Items" box and Mark them for Deletion
     foreach (ImapMessage msg in messages)
     {
       if (msg.Seen) //If Seen flag is set
       {
          msg.CopyTo(deletedBox); //Copy to "Deleted Items" box
          msg.Delete = true; //Set deleted flag in "INBOX"
       }
     }

     //Permanently Remove Copied Messages from "INBOX"
     inboxBox.Purge();

     //Update Messages Count in "Deleted Items"
     deletedBox.Refresh();

     //Display new Messages Counts
     labelDisplay.Text = inboxBox.Messages.Count.ToString() + "  " + deletedBox.Messages.Count.ToString();

     //Logout from server
     imap1.Logout();
   }
   catch (Exception ex)
   {
      //Show MessageBox if error occurs
      MessageBox.Show(ex.Message, "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
   }
}

Remarks

The Imap.Login method logs into server at the port specified by port with the specified username and password. If Imap.AutoList is true, Imap.Login will also perform a list of all top-level mailboxes and will set Imap.CurrentMailbox to the Mailbox object representing "INBOX", if one exists.

The Imap.Login method logs into server with the specified username and password. If Imap.AutoList is true, Imap.Login will also perform a list of all top-level mailboxes and will set Imap.CurrentMailbox to the Mailbox object representing "INBOX", if one exists.

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

Documentation Version 3.2
© 2010 Dart Communications. All Rights Reserved.