PowerTCP Mail for .NET
Authenticate Method (Pop)
Example 




If true, MessageBase.Size is initialized for all messages.
If true, MessageBase.Uid is initialized for all messages.
Authenticate the client using parameters in Pop.Session, and populate Messages.
Syntax
Public Sub Authenticate( _
   ByVal getSizes As Boolean, _
   ByVal getUids As Boolean _
) 
Dim instance As Pop
Dim getSizes As Boolean
Dim getUids As Boolean
 
instance.Authenticate(getSizes, getUids)
public void Authenticate( 
   bool getSizes,
   bool getUids
)
public: void Authenticate( 
   bool getSizes,
   bool getUids
) 
public:
void Authenticate( 
   bool getSizes,
   bool getUids
) 

Parameters

getSizes
If true, MessageBase.Size is initialized for all messages.
getUids
If true, MessageBase.Uid is initialized for all messages.
Exceptions
ExceptionDescription
ProtocolExceptionBad POP protocol response received from server.
System.Net.Sockets.SocketExceptionThe requested address is not valid in its context.
Remarks

SSL security is negotiated if Session.Security.Encrypt == Encrypt.Explicit.

Pop.Messages.Size is initialized.

PopMessage.Get may be used to retrieve any message. The Pop component will remain logged in until Close is called.

Example
This example demonstrates connecting to a Pop server, with options for encryption (Explicit/Implicit), and authenticating the user.
using System.Security.Cryptography.X509Certificates;
using System.Security.Authentication;
using System.Net.Security;

/// <summary>
/// Connects to a Pop server, optionally using encryption (Explicit/Implicit), and authenticates the user.
/// </summary>
/// <param name="myPop">The Pop instance to connect and authenticate</param>
/// <param name="hostNameOrAddress">The server's hostname or IP address</param>
/// <param name="auth">Authentication method to use. 'Auto' is suitable for most circumstances.</param>
/// <param name="username">Username</param>
/// <param name="password">Password</param>
/// <param name="encryption">Controls whether SSL/TLS is used, and the implementation. None/Explicit/Implicit.</param>
private void ConnectAndAuthenticate(Pop myPop, string hostNameOrAddress, Authentication auth, string username, string password, Encrypt encryption)
{
    if (encryption != Encrypt.None)
    {
        //Set the method of encryption - Implicit/Explicit
        myPop.Session.Security.Encrypt = encryption;

        //Optionally set the protocols available for SSL/TLS negotiation (defaults to SslProtocols.Default)
        //TLS 1.1/1.2 requires .NET 4.5+. See the SslProtocols MSDN documentation for more information.
        myPop.Session.Security.Protocols = SslProtocols.Tls | SslProtocols.Ssl3;

        //Specify the server certificate validation callback
        myPop.Session.Security.ValidationCallback = remoteCertificateValidation;
    }

    //Set the server address and port. If the server uses a non-standard port, it should be substituted here.
    //GetDefaultPort() returns the common port used for the security configuration.
    myPop.Session.RemoteEndPoint = new IPEndPoint(hostNameOrAddress, Pop.GetDefaultPort(myPop.Session));

    //Connect to the server.
    myPop.Connect();

    //Authenticate the user.
    myPop.Session.Username = username;
    myPop.Session.Password = password;
    myPop.Session.Authentication = auth;
    myPop.Authenticate(false, true);
}

private bool remoteCertificateValidation(Object sender, X509Certificate remoteCertificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
    //For this simple snippet, accept all server certificates. Please see the 'Security' top-level help topics, or 
    //the System.Net.Security.RemoteCertificateValidationCallback MSDN documentation, for more information.
    return true;
}
Imports System.Security.Cryptography.X509Certificates
Imports System.Security.Authentication
Imports System.Net.Security

''' <summary>
''' Connects to a Pop server, optionally using encryption (Explicit/Implicit), and authenticates the user.
''' </summary>
''' <param name="myPop">The Pop instance to connect and authenticate</param>
''' <param name="hostNameOrAddress">The server's hostname or IP address</param>
''' <param name="auth">Authentication method to use. 'Auto' is suitable for most circumstances.</param>
''' <param name="username">Username</param>
''' <param name="password">Password</param>
''' <param name="encryption">Controls whether SSL/TLS is used, and the implementation. None/Explicit/Implicit.</param>
Private Sub ConnectAndAuthenticate(ByVal myPop As Pop, ByVal hostNameOrAddress As String, ByVal auth As Authentication, ByVal username As String, ByVal password As String, ByVal encryption As Encrypt)
    If encryption <> Encrypt.None Then
        'Set the method of encryption - Implicit/Explicit
        myPop.Session.Security.Encrypt = encryption

        'Optionally set the protocols available for SSL/TLS negotiation (defaults to SslProtocols.Default)
        'TLS 1.1/1.2 requires .NET 4.5+. See the SslProtocols MSDN documentation for more information.
        myPop.Session.Security.Protocols = SslProtocols.Tls Or SslProtocols.Ssl3

        'Specify the server certificate validation callback
        myPop.Session.Security.ValidationCallback = AddressOf remoteCertificateValidation
    End If

    'Set the server address and port. If the server uses a non-standard port, it should be substituted here.
    'GetDefaultPort() returns the common port used for the security configuration.
    myPop.Session.RemoteEndPoint = New IPEndPoint(hostNameOrAddress, Pop.GetDefaultPort(myPop.Session))

    'Connect to the server.
    myPop.Connect()

    'Authenticate the user.
    myPop.Session.Username = username
    myPop.Session.Password = password
    myPop.Session.Authentication = auth
    myPop.Authenticate(False, True)
End Sub

Private Function remoteCertificateValidation(ByVal sender As Object, ByVal remoteCertificate As X509Certificate, ByVal chain As X509Chain, ByVal sslPolicyErrors As SslPolicyErrors) As Boolean
    'For this simple snippet, accept all server certificates. Please see the 'Security' top-level help topics, or 
    'the System.Net.Security.RemoteCertificateValidationCallback MSDN documentation, for more information.
    Return True
End Function
See Also

Reference

Pop Class
Pop Members


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