Issue a custom command to POP3 server
You can send any command to POP3 server using Mail.dll and receive servers’s response easy.
In this example we will issue LIST command. LIST command is used to check the email size without downloading it from the POP3 server.
There are 2 versions of the LIST command. First takes message number parameter:
LIST messageNumber
We are asking for specific message here, which means that we expect to receive single line response.
Remember that message numbers on POP3 servers start from 1.
// C# version using System; using Limilabs.Client.POP3; class Program { static void Main(string[] args) { using (Pop3 pop3 = new Pop3()) { pop3.Connect("server.example.com"); pop3.Login("user", "password"); Pop3Response response = pop3.SendCommand("LIST " + 1); // We expect string in following format: "0 32768" string sizeInBytes = response.Message.Split(' ')[1]; Console.WriteLine(sizeInBytes); pop3.Close(); } } };
' VB.NET version Imports System Imports Limilabs.Client.POP3 Public Module Module1 Public Sub Main(ByVal args As String()) Using pop3 As New Pop3() pop3.Connect("server.example.com") pop3.Login("user", "password") Dim response As Pop3Response = pop3.SendCommand("LIST " + 1) ' We expect string in following format: "0 32768" Dim sizeInBytes As String = response.Message.Split(" "c)(1) Console.WriteLine(sizeInBytes) pop3.Close() End Using End Sub End Module
Second version is LIST command without any arguments:
LIST
It gets the size of every message that is currently stored on the POP3 server – server replies with multi-line response:
// C# version using System; using Limilabs.Mail; using Limilabs.Client.POP3; class Program { static void Main(string[] args) { using (Pop3 pop3 = new Pop3()) { pop3.Connect("server.company.com"); pop3.Login("user", "password"); Pop3Response response = pop3.SendMultiLineCommand("LIST"); foreach(string line in response.GetLines()) { // We expect following format: "0 32768" string[] tmp = line.Split(' '); Console.WriteLine("Message number {0} is {1} bytes long.", tmp[0], tmp[1]); } pop3.Close(); } } };
' VB.NET version Imports System Imports Limilabs.Client.POP3 Public Module Module1 Public Sub Main(ByVal args As String()) Using pop3 As New Pop3() pop3.Connect("server.company.com") pop3.Login("user", "password") Dim response As Pop3Response = pop3.SendMultiLineCommand("LIST") For Each line As String In response.GetLines() ' We expect following format: "0 32768" Dim tmp As String() = line.Split(" "c) Console.WriteLine("Message number {0} is {1} bytes long.", tmp(0), tmp(1)) Next pop3.Close() End Using End Sub End Module
August 19th, 2017 at 16:12
Can I use NTLM with your Pop3 component? Please provide a complete example.
August 19th, 2017 at 21:00
@Kashif,
Just use use one of the Pop3.LoginSSPI method overloads:
LoginSSPI(SSPIMechanism.NTLM, string target)
LoginSSPI(SSPIMechanism.NTLM)
LoginSSPI(SSPIMechanism.NTLM, string userWithDomain, string password)