Rebex POP3

POP3, SMTP, MIME, S/MIME libraries for .NET

Download 30-day free trial Buy from $199
More .NET libraries

Back to feature list...

Connecting

Connecting to servers using POP3 protocol 

To connect to a POP3 server running on default port (110), call the single-parameter Connect method. A plain (unencrypted) connection is established.

// create POP3 client instance
var client = new Rebex.Net.Pop3();

// connect to a server
client.Connect(hostname);
' create POP3 client instance
Dim client = New Rebex.Net.Pop3()

' connect to a server
client.Connect(hostname)
Tip: To connect to a server running on another port, just pass the port number to the Connect method as an additional argument.

Connecting to servers using explicit or implicit TLS/SSL 

To establish a secure TLS/SSL connection to a POP3 server, use the Connect method with SslMode argument.

Tip: Learn about the difference between explicit and implicit TLS/SSL modes.

// create POP3 client instance
var client = new Rebex.Net.Pop3();

// connect to a server using explicit TLS/SSL
client.Connect(hostname, SslMode.Explicit);

// connect to a server using implicit TLS/SSL
//client.Connect(hostname, SslMode.Implicit);
' create POP3 client instance
Dim client = New Rebex.Net.Pop3()

' connect to a server using explicit TLS/SSL
client.Connect(hostname, SslMode.Explicit)

' connect to a server using implicit TLS/SSL
'client.Connect(hostname, SslMode.Implicit);

Server certificate is validated automatically by Rebex POP3, but you can customize the validation process as well.

Tip: For advanced security options, see TLS/SSL core section.

Switching to encrypted communication 

It's also possible to establish a plain (unencrypted) connection first and upgrade to TLS/SSL later using the Secure method.

// create POP3 client instance
var client = new Rebex.Net.Pop3();

// connect to a server on default (not-secured) port 110
client.Connect(hostname);

// secure the connection with TLS/SSL
client.Secure();

// authenticate securely
client.Login(username, password);
' create POP3 client instance
Dim client = New Rebex.Net.Pop3()

' connect to a server on default (not-secured) port 110
client.Connect(hostname)

' secure the connection with TLS/SSL
client.Secure()

' authenticate securely
client.Login(username, password)

Setting connection options 

There are various connection options such as character sets, proxies, href='https://www.rebex.net/doc/api/Rebex.Net.Pop3Extensions.html'>POP3 extensions, and more.

// create POP3 client instance
// ...

// use SOCKS5 proxy
client.Proxy.ProxyType = ProxyType.Socks5;
// ...

// set UTF-8 encoding for commands and responses
client.Encoding = Encoding.UTF8;

// allow only TLS 1.1
client.Settings.SslAllowedVersions = TlsVersion.TLS11;

// connect, log in, retrieve emails
// ...
' create POP3 client instance
' ...

' use SOCKS5 proxy
client.Proxy.ProxyType = ProxyType.Socks5
' ...

' set UTF-8 encoding for commands and responses
client.Encoding = Encoding.UTF8

' allow only TLS 1.1
client.Settings.SslAllowedVersions = TlsVersion.TLS11

' connect, log in, retrieve emails
' ...

Getting info about the connection 

Once connected (or authenticated), you can get useful information about the current connection such as server name, server port or user name. Don't be afraid - user's password is not stored with the connection.

// create POP3 client instance
var client = new Rebex.Net.Pop3();

// connect to a server
client.Connect(hostname, SslMode.Explicit);

// display info
Console.WriteLine("Connected to {0}:{1}.", client.ServerName, client.ServerPort);

// authenticate
client.Login(username, password);

// display info to the user
Console.WriteLine("Logged on as {0}.", client.UserName);
' create POP3 client instance
Dim client = New Rebex.Net.Pop3()

' connect to a server
client.Connect(hostname, SslMode.Explicit)

' display info
Console.WriteLine("Connected to {0}:{1}.", client.ServerName, client.ServerPort)

' authenticate
client.Login(username, password)

' display info to the user
Console.WriteLine("Logged on as {0}.", client.UserName)

Getting info about TLS/SSL connection 

To get information about SSL connection, use TlsSocket property.

// create POP3 client instance
var client = new Rebex.Net.Pop3();

// connect to a server
client.Connect(hostname, SslMode.Explicit);

// Cipher property contains a lot of information about the current cipher
Console.WriteLine("TLS cipher info: {0}", client.TlsSocket.Cipher);

// ServerCertificate property provides access to server certificate
// the first certificate in the chain is the server's certificate
CertificateChain chain = client.TlsSocket.ServerCertificate;
Console.WriteLine("Server's certificate info: Subject: {0}, Issuer: {1}",
    chain[0].GetSubject(), chain[0].GetIssuer());
' create POP3 client instance
Dim client = New Rebex.Net.Pop3()

' connect to a server
client.Connect(hostname, SslMode.Explicit)

' Cipher property contains a lot of information about the current cipher
Console.WriteLine("TLS cipher info: {0}", client.TlsSocket.Cipher)

' ServerCertificate property provides access to server certificate
' the first certificate in the chain is the server's certificate
Dim chain As CertificateChain = client.TlsSocket.ServerCertificate
Console.WriteLine("Server's certificate info: Subject: {0}, Issuer: {1}",
                  chain(0).GetSubject(), chain(0).GetIssuer())

Back to feature list...