User Authentication and SSL Connection


To logon POP3 or IMAP4 server, the user authentication is the first step. EAGetMail supports most authentication mechanisms including: LOGIN, CRAM-MD5 and AUTH NTLM. The authentication mechanism must be specified by EAGetMail.ServerAuthType enumeration.

The ServerAuthType.AuthCRAM5 and ServerAuthType.AuthNTLM are "Secure Password Authentication", the password is encrypted by challenge code returned by server before the password is sent to the server. In contrary, the password is sent to server in plain format with ServerAuthType.AuthLogin. Therefore, using ServerAuthType.AuthCRAM5 and ServerAuthType.AuthNTLM is more secure than using ServerAuthType.AuthLogin. However, not every mail server supports ServerAuthType.AuthCRAM5 and ServerAuthType.AuthNTLM. Especially ServerAuthType.AuthNTLM, only Microsoft Exchange Server or Windows POP3 Service supports it. Based on POP3/IMAP4 rfc, ServerAuthType. AuthLogin is supported by every POP3/IMAP4 server, so if you can't detect what authentication mechanisms that the server supports, please use ServerAuthType.AuthLogin.

Now most email servers use SSL/TLS + AuthLogin.

Example

[C# - POP3 Server - User Authentication]
MailServer oServer  = new MailServer("myserveraddress", 
    "myuser", "mypassword", false, 
    ServerAuthType.AuthLogin, ServerProtocol.Pop3);
[VB - POP3 Server - User Authentication]
Dim oServer  As New MailServer("myserveraddress", 
    "myuser", "mypassword", False, 
    ServerAuthType.AuthLogin, ServerProtocol.Pop3);

SSL/TLS Connection

SSL connection encrypts data between the POP3 & IMAP4 component and mail server to protects user, password and email content in TCP/IP level. Now this technology is commonly used and many email servers are deployed with SSL such as gmail. The mail server usually deploys SSL on another port( POP3 on 995 or other port, IMAP4 on 993 or other port ), you may query it from your server administrator) directly. There are two ways to deploy SSL/TLS on POP3/IMAP4 server:

TLS 1.2 Encryption

TLS is the successor of SSL, EAGetMail supports SSL 3.0/TLS1.0 - 1.2 very well. In EAGetMail, SSLConnectType.ConnectTLS doesn't mean TLS encryption, it means TLS command POP3/IMAP protocol.

You don't have to set any property to enable TLS 1.2 encryption. If your server requires TLS 1.2 encryption, TLS 1.2 encryption is used automatically with SSLConnectType.ConnectTLS, SSLConnectType.ConnectSSL or SSLConnectType.ConnectSSLAuto.

To enable TLS 1.2 on some legacy systems, you have to install required update/packages:
Enable TLS 1.2 on Windows XP/2003/2008/7/2008 R2

Example

[C# - SSL/TLS Setting]
//connect pop3 server by normal TCP/IP without SSL connection
MailServer oServer  = new MailServer("myserveraddress", 
    "myuser", "mypassword",  false, 
    ServerAuthType.AuthLogin, ServerProtocol.Pop3);
 
//connect imap4 server by normal TCP/IP without SSL connection    
MailServer oServer  = new MailServer("myserveraddress", 
    "myuser", "mypassword", false, 
    ServerAuthType.AuthLogin, ServerProtocol.Imap4 );
    
//connect pop3 server by SSL connection on default port(995)
MailServer oServer  = new MailServer("myserveraddress", 
    "myuser", "mypassword", true, 
    ServerAuthType.AuthLogin, ServerProtocol.Pop3);
   
//connect imap4 server by SSL connection on default port(993) 
MailServer oServer  = new MailServer("myserveraddress", 
    "myuser", "mypassword", true, 
    ServerAuthType.AuthLogin, ServerProtocol.Imap4 );

//connect pop3 server by SSL connection on anther port(777)
MailServer oServer  = new MailServer("myserveraddress", 
    "myuser", "mypassword", true, 
    ServerAuthType.AuthLogin, ServerProtocol.Pop3);
oServer.Port = 777;

//connect imap4 server by SSL connection on anther port(778)
MailServer oServer  = new MailServer("myserveraddress", 
    "myuser", "mypassword", true, 
    ServerAuthType.AuthLogin, ServerProtocol.Pop3);
oServer.Port = 778;


// Exchange Web Service
MailServer oServer  = new MailServer("myserveraddress", 
    "myuser", "mypassword", false, 
    ServerAuthType.AuthLogin, ServerProtocol.ExchangeEWS);

// Exchange WebDAV
MailServer oServer  = new MailServer("myserveraddress", 
    "myuser", "mypassword", false, 
    ServerAuthType.AuthLogin, ServerProtocol.ExchangeWebDAV);


// Exchange Web Service SSL
MailServer oServer  = new MailServer("myserveraddress", 
    "myuser", "mypassword", true, 
    ServerAuthType.AuthLogin, ServerProtocol.ExchangeEWS);

// Exchange WebDAV SSL
MailServer oServer  = new MailServer("myserveraddress", 
    "myuser", "mypassword", true, 
    ServerAuthType.AuthLogin, ServerProtocol.ExchangeWebDAV);

// Retrieve email by SSL connection with STARTTLS or TLS command switching
// POP3 TLS
MailServer oServer  = new MailServer("myserveraddress", 
    "myuser", "mypassword", true, 
    ServerAuthType.AuthLogin, ServerProtocol.Pop3);
oServer.Port = 110;
oServer.SSLType = SSLConnectType.ConnectTLS;

// IMAP4 STARTTLS
MailServer oServer  = new MailServer("myserveraddress", 
    "myuser", "mypassword", true, 
    ServerAuthType.AuthLogin, ServerProtocol.Imap4);
oServer.Port = 143;
oServer.SSLType = SSLConnectType.ConnectTLS;
 
[VB - SSL/TLS Setting]
' Retrieve email by normal TCP/IP without SSL connection
' POP3
Dim oServer As New MailServer("myserveraddress", "myuser", "mypassword", _
     False, ServerAuthType.AuthLogin, ServerProtocol.Pop3)

' IMAP4
Dim oServer As New MailServer("myserveraddress", "myuser", "mypassword", _
    False, ServerAuthType.AuthLogin, ServerProtocol.Imap4)

' Retrieve email over SSL connection with direct SSL.
' POP3 SSL
Dim oServer As New MailServer("myserveraddress", "myuser", "mypassword", _ 
    True, ServerAuthType.AuthLogin, ServerProtocol.Pop3)
oServer.Port = 995

' IMAP4 SSL
Dim oServer As New MailServer("myserveraddress", "myuser", "mypassword", _ 
    True, ServerAuthType.AuthLogin, ServerProtocol.Imap4)
oServer.Port = 993

' Retrieve email by SSL connection with STARTTLS or TLS command switching
' POP3 TLS
Dim oServer As New MailServer("myserveraddress", "myuser", "mypassword", _
    True, ServerAuthType.AuthLogin, ServerProtocol.Pop3)
oServer.Port = 110
oServer.SSLType = SSLConnectType.ConnectTLS

' IMAP4 STARTTLS
Dim oServer As New MailServer("myserveraddress", "myuser", "mypassword", _
    True, ServerAuthType.AuthLogin, ServerProtocol.Imap4)
oServer.Port = 143
oServer.SSLType = SSLConnectType.ConnectTLS


' Exchange WebDAV
Dim oServer As New MailServer("myserveraddress", _
    "myuser", "mypassword", False,  _
    ServerAuthType.AuthLogin, ServerProtocol.ExchangeWebDAV)

' Exchange Web Service SSL
Dim oServer As New MailServer("myserveraddress", _
    "myuser", "mypassword", True, _
    ServerAuthType.AuthLogin, ServerProtocol.ExchangeEWS)

' Exchange WebDAV SSL
Dim oServer As New MailServer("myserveraddress", _ 
    "myuser", "mypassword", True, _ 
    ServerAuthType.AuthLogin, ServerProtocol.ExchangeWebDAV)

    
[C++/CLI - SSL/TLS Setting]
// Retrieve email by normal TCP/IP without SSL connection
// POP3
MailServer ^oServer  = gcnew MailServer("myserveraddress", 
	"myuser", "mypassword", ServerProtocol::Pop3);

// IMAP4
MailServer ^oServer  = gcnew MailServer("myserveraddress", 
    "myuser", "mypassword", ServerProtocol::Imap4);

// Retrieve email over SSL connection with direct SSL.
// POP3 SSL
MailServer ^oServer  = gcnew MailServer("myserveraddress", 
    "myuser", "mypassword", ServerProtocol::Pop3);
oServer->SSLConnection = true;
oServer->Port = 995;

// IMAP4 SSL
MailServer ^oServer  = gcnew MailServer("myserveraddress", 
    "myuser", "mypassword", ServerProtocol::Imap4);
oServer->SSLConnection = true;
oServer->Port = 993;

// Retrieve email by SSL connection with STARTTLS or TLS command switching
// POP3 TLS
MailServer ^oServer  = gcnew MailServer("myserveraddress", 
    "myuser", "mypassword", ServerProtocol::Pop3);
oServer->SSLConnection = true;
oServer->Port = 110;
oServer->SSLType = SSLConnectType::ConnectTLS;

// IMAP4 STARTTLS
MailServer ^oServer  = gcnew MailServer("myserveraddress", 
    "myuser", "mypassword", ServerProtocol::Imap4);
oServer->SSLConnection = true;
oServer->Port = 143;
oServer->SSLType = SSLConnectType::ConnectTLS;

// Exchange WebDAV
MailServer ^oServer  = gcnew MailServer("myserveraddress", 
    "myuser", "mypassword", false, 
    ServerAuthType.AuthLogin, ServerProtocol::ExchangeWebDAV);

// Exchange Web Service SSL
MailServer ^oServer  = gcnew MailServer("myserveraddress", 
    "myuser", "mypassword", true, 
    ServerAuthType.AuthLogin, ServerProtocol::ExchangeEWS);

// Exchange WebDAV SSL
MailServer ^oServer  = gcnew MailServer("myserveraddress", 
    "myuser", "mypassword", true, 
    ServerAuthType.AuthLogin, ServerProtocol::ExchangeWebDAV);
    

See Also

Using EAGetMail POP3 and IMAP4 Component
Enable TLS 1.2 on Windows XP/2003/2008/7/2008 R2
Using Gmail IMAP4 OAUTH
Using Gmail/GSuite Service Account + IMAP4 OAUTH
Using Office365 EWS OAUTH
Using Office365 EWS OAUTH in Background Service
Using Hotmail IMAP4 OAUTH
Digital Signature and E-mail Encryption/Decryption
Unique Identifier (UIDL) in POP3 and IMAP4 protocol
Parse Bounced Email (delivery-report)
Work with winmail.dat (TNEF Parser)
EAGetMail Namespace References
EAGetMail POP3 and IMAP4 Component Samples

Online Tutorials

Read Email over SSL/TLS Connection in C# - Tutorial
Read Email from Gmail Account in C# - Tutorial
Read Email from Yahoo Account in C# - Tutorial
Read Email from Hotmail Account in C# - Tutorial

Read Email over SSL/TLS Connection in VB.NET - Tutorial
Read Email from Gmail Account in VB.NET - Tutorial
Read Email from Yahoo Account in VB.NET - Tutorial
Read Email from Hotmail Account in VB.NET - Tutorial

Read Email over SSL/TLS Connection C++/CLI - Tutorial
Read Email from Gmail Account in C++/CLI - Tutorial
Read Email from Yahoo Account in C++/CLI - Tutorial
Read Email from Hotmail Account in C++/CLI - Tutorial