MailBee. NET Objects Tutorials

POP3 authentication

To log in a POP3 account, you must supply at least the valid account name (also called user name, login, etc) and the password.

C#

Pop3 pop = new Pop3();
pop.Connect("mail.domain.com", 995);
pop.Login("jdoe", "secret");

VB.NET

Dim pop As New Pop3() 
pop.Connect("mail.domain.com", 995)
pop.Login("jdoe", "secret")

The above code connects to the POP3 server via SSL/TLS port. Most servers won't allow clear-text authentication unless you connect via SSL/TLS.

Also, many servers require the login name to include the domain part (e.g. jdoe@domain.com).

Many POP3 servers support more than one authentication mechanism to provide secure authentication methods. By default, the more secure authentication method is being used. You can override this behaviour (for instance, if the server incorrectly implements certain authentication method) using other overloads of Login method. For instance, the code above forces MailBee to try APOP method only (APOP is the secure authentication method specific to the POP3 protocol, supported by many POP3 servers):

C#

Pop3 pop = new Pop3();
pop.Connect("mail.domain.com");
pop.Login("jdoe", "secret", AuthenticationMethods.Apop);

VB.NET

Dim pop As New Pop3() 
pop.Connect("mail.domain.com")
pop.Login("jdoe", "secret", AuthenticationMethods.Apop)

Or, you can force MailBee to try simple authentication methods first and use secure methods only if simple methods are not supported by the server. The sample code below uses the simplest available authentication method in order to log in. Thus, if the server supports basic clear-text USER/PASS authentication, it will be used. If, however, USER/PASS method is not enabled (let's imagine only secure SASL NTLM is supported by the server), MailBee will use that method.

C#

pop.Login("jdoe", "secret", AuthenticationMethods.Auto, AuthenticationOptions.PreferSimpleMethods, null);

VB.NET

pop.Login("jdoe", "secret", AuthenticationMethods.Auto, AuthenticationOptions.PreferSimpleMethods, Nothing)

MailBee also supports Windows Integrated Authentication (login using the credentials of the currently logged Windows user). It can be used as follows:

C#

pop.Login(null, null, AuthenticationMethods.SaslNtlm);

VB.NET

pop.Login(Nothing, Nothing, AuthenticationMethods.SaslNtlm)

However, it cannot be used if you're developing ASP.NET application which runs under anonymous IIS or ASP.NET user context (because the currently logged user will be the IIS user rather than the human which is using the application).

Nowadays, OAuth 2.0 authentication becomes more common (although it's mostly supported by IMAP servers). See OAuth 2.0 in Windows, .NET Core, and ASP.NET MVC apps for details.