Glossary Item Box
It is usually not necessary to explicitly send commands to a POP server. Almost all commands that could conceivably be sent to a POP server are encapsulated by high-level methods. For example, depending on your Pop component settings, calling Login could cause the "USER", "PASS", "STAT", "LIST", and "RETR" commands to be automatically sent to the server. There are rare occasions when you must send a command to a POP server that is not encapsulated by a high-level method. This is often the case with a POP server that is operating outside of the RFC spec that requires proprietary commands.
The Pop component uses the Tcp component for the connection, which is exposed through the Connection property. To send commands, simply call the methods of this object (such as Pop.Connection.Send to send commands and Pop.Connection.Receive to receive commands)
To send a command to a POP server, use the following steps. For the purposes of this example, the "STAT" command (which causes the POP server to return the amount of messages and size of all messages) is used.
[Visual Basic, C#] Place the following code at the top of your file.
[C#] using Dart.PowerTCP.Mail; [Visual Basic] Imports Dart.PowerTCP.Mail
[Visual Basic, C#] Place the following code in the Click event of the button added to the form in step 3.
[C#] // Do not automatically get messages after logging in. pop1.AutoGet = MessageSection.None; // Do not close the connection. pop1.AutoLogout = false; [Visual Basic] ' Do not automatically get messages after logging in. Pop1.AutoGet = None ' Do not close the connection. Pop1.AutoLogout = False
[Visual Basic, C#] Place this code directly after the code from step 5.
[C#]
// Login
pop1.Login("mail.test.com", "test", "pass");
[Visual Basic]
' Login
Pop1.Login("mail.test.com", "test", "pass")
[Visual Basic, C#]
[C#]
pop1.Connection.Send("STAT\r\n");
[Visual Basic]
Pop1.Connection.Send("STAT" + vbCrLf)
[Visual Basic, C#]
[C#] // Receive the response. Segment seg = pop1.Connection.Receive(); [Visual Basic] ' Receive the response. Dim seg As Segment = Pop1.Connection.Receive()
[Visual Basic, C#]
[C#]
// Split the response.
char ch = ' ';
string[] responseparts = seg.ToString().Split(ch);
// Check for good response.
if(responseparts[0] == "+OK")
{
Debug.WriteLine("Number of messages: " + responseparts[1]);
Debug.WriteLine("Size of messages: " + responseparts[2]);
}
else
{
// Bad response from server.
Debug.WriteLine(seg.ToString());
}
// Be sure to close the connection.
pop1.Close();
[Visual Basic]
' Split the response.
Dim ch As Char = " "
Dim responseparts() = seg.ToString().Split(ch)
' Check for good response.
If responseparts(0) = "+OK" Then
Debug.WriteLine("Number of messages: " + responseparts(1))
Debug.WriteLine("Size of messages: " + responseparts(2))
Else
' Bad response from server.
Debug.WriteLine(seg.ToString())
End If
' Be sure to close the connection.
Pop1.Close()
Send comments on this topic.
Documentation version 3.1.
© 2009 Dart Communications. All rights reserved.