Initializes a new instance of the Pop3Client class and connects to the specified port on
the specified host, optionally using the Secure Socket Layer (SSL) security protocol and
attempts to authenticate with the server using the specified authentication method and
credentials.
Namespace: S22.Pop3Assembly: S22.Pop3 (in S22.Pop3.dll) Version: 1.1.4653.26443 (1.1.0.0)
Syntax
C# |
---|
public Pop3Client( string hostname, int port, string username, string password, AuthMethod method = AuthMethod.Login, bool ssl = false, RemoteCertificateValidationCallback validate = null ) |
Parameters
- hostname
- Type: System..::..String
The DNS name of the server to which you intend to connect.
- port
- Type: System..::..Int32
The port number of the server to which you intend to connect.
- username
- Type: System..::..String
The username with which to login in to the POP3 server.
- password
- Type: System..::..String
The password with which to log in to the POP3 server.
- method (Optional)
- Type: S22.Pop3..::..AuthMethod
The requested method of authentication. Can be one of the values of the AuthMethod enumeration.
- ssl (Optional)
- Type: System..::..Boolean
Set to true to use the Secure Socket Layer (SSL) security protocol.
- validate (Optional)
- Type: System.Net.Security..::..RemoteCertificateValidationCallback
Delegate used for verifying the remote Secure Sockets Layer (SSL) certificate which is used for authentication. Set this to null if not needed
Examples
This example demonstrates how to establish a secure connection, login
to a POP3 server and check for new messages.
CopyC#

/* Connect to Gmail's POP3 server on port 995 using SSL */ try { Pop3Client Client = new Pop3Client("pop.gmail.com", 995, "My_Username", "My_Password", true, AuthMethod.Login); MessageInfo[] info = Client.GetStatus(); if(info.Length > 0) Console.WriteLine(info.Length + " new messages"); else Console.WriteLine("No new messages"); Client.Dispose(); } catch(InvalidCredentialsException) { Console.WriteLine("The server rejected the supplied credentials"); }
Exceptions
Exception | Condition |
---|---|
System..::..ArgumentOutOfRangeException | The port parameter is not between MinPort and MaxPort. |
System..::..ArgumentNullException | The hostname parameter is null. |
System.Net.Sockets..::..SocketException | An error occurred while accessing the socket used for establishing the connection to the POP3 server. Use the ErrorCode property to obtain the specific error code |
System.Security.Authentication..::..AuthenticationException | An authentication error occured while trying to establish a secure connection. |
S22.Pop3..::..BadServerResponseException | Thrown if an unexpected response is received from the server upon connecting. |
S22.Pop3..::..InvalidCredentialsException | Thrown if authentication using the supplied credentials failed. |