<div class="meta" robots="noindex">

</div>

Class

# POP3Socket

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="warning">

<div class="title">

Warning

</div>

This item was deprecated in version 2018r4. Please use `POP3SecureSocket</api/networking/pop3securesocket>` as a replacement.

</div>

## Description

Used to retrieve and manage messages on a POP3 mail server.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                            | Type                                                 | Read-Only | Shared |
|-------------------------------------------------|------------------------------------------------------|-----------|--------|
| `Address<pop3socket.address>`                   | `String</api/data_types/string>`                     |           |        |
| `BytesAvailable<pop3socket.bytesavailable>`     | `Integer</api/data_types/integer>`                   | ✓         |        |
| `BytesLeftToSend<pop3socket.byteslefttosend>`   | `Integer</api/data_types/integer>`                   | ✓         |        |
| `EncryptPassword<pop3socket.encryptpassword>`   | `Boolean</api/data_types/boolean>`                   |           |        |
| `Handle<pop3socket.handle>`                     | `Integer</api/data_types/integer>`                   | ✓         |        |
| `IsConnected<pop3socket.isconnected>`           | `Boolean</api/data_types/boolean>`                   | ✓         |        |
| `LocalAddress<pop3socket.localaddress>`         | `String</api/data_types/string>`                     | ✓         |        |
| `NetworkInterface<pop3socket.networkinterface>` | `NetworkInterface</api/networking/networkinterface>` |           |        |
| `Password<pop3socket.password>`                 | `String</api/data_types/string>`                     |           |        |
| `Port<pop3socket.port>`                         | `Integer</api/data_types/integer>`                   |           |        |
| `RemoteAddress<pop3socket.remoteaddress>`       | `String</api/data_types/string>`                     | ✓         |        |
| `Username<pop3socket.username>`                 | `String</api/data_types/string>`                     |           |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                                      | Parameters                                                                                                   | Returns                            | Shared |
|-----------------------------------------------------------|--------------------------------------------------------------------------------------------------------------|------------------------------------|--------|
| `CheckServerConnection<pop3socket.checkserverconnection>` |                                                                                                              |                                    |        |
| `Close<pop3socket.close>`                                 |                                                                                                              |                                    |        |
| `Connect<pop3socket.connect>`                             |                                                                                                              |                                    |        |
| `CountMessages<pop3socket.countmessages>`                 |                                                                                                              |                                    |        |
| `DeleteMessage<pop3socket.deletemessage>`                 | Index As `Integer</api/data_types/integer>`                                                                  |                                    |        |
| `Disconnect<pop3socket.disconnect>`                       |                                                                                                              |                                    |        |
| `DisconnectFromServer<pop3socket.disconnectfromserver>`   |                                                                                                              |                                    |        |
| `EndOfFile<pop3socket.endoffile>`                         |                                                                                                              | `Boolean</api/data_types/boolean>` |        |
| `Flush<pop3socket.flush>`                                 |                                                                                                              |                                    |        |
| `Listen<pop3socket.listen>`                               |                                                                                                              |                                    |        |
| `ListMessages<pop3socket.listmessages>`                   | \[Index As `Integer</api/data_types/integer>`\]                                                              |                                    |        |
| `Lookahead<pop3socket.lookahead>`                         | \[Encoding As `TextEncoding</api/text/encoding_text/textencoding>`\]                                         | `String</api/data_types/string>`   |        |
| `Poll<pop3socket.poll>`                                   |                                                                                                              |                                    |        |
| `Purge<pop3socket.purge>`                                 |                                                                                                              |                                    |        |
| `Read<pop3socket.read>`                                   | Count As `Integer</api/data_types/integer>`, \[Enc As `TextEncoding</api/text/encoding_text/textencoding>`\] | `String</api/data_types/string>`   |        |
| `ReadAll<pop3socket.readall>`                             | \[Encoding As `TextEncoding</api/text/encoding_text/textencoding>`\]                                         | `String</api/data_types/string>`   |        |
| `RetrieveLines<pop3socket.retrievelines>`                 | Index As `Integer</api/data_types/integer>`, LineCount As `Integer</api/data_types/integer>`                 |                                    |        |
| `RetrieveMessage<pop3socket.retrievemessage>`             | Index As `Integer</api/data_types/integer>`                                                                  |                                    |        |
| `RollbackServer<pop3socket.rollbackserver>`               |                                                                                                              |                                    |        |
| `SendServerCommand<pop3socket.sendservercommand>`         | Command As `String</api/data_types/string>`                                                                  |                                    |        |
| `Write<pop3socket.write>`                                 | Data As `String</api/data_types/string>`                                                                     |                                    |        |

## Events

<div class="rst-class">

table-centered_column_4

</div>

| Name                                                      | Parameters                                                                                                                                         | Returns |
|-----------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|---------|
| `ConnectionEstablished<pop3socket.connectionestablished>` |                                                                                                                                                    |         |
| `Disconnected<pop3socket.disconnected>`                   |                                                                                                                                                    |         |
| `ListReceived<pop3socket.listreceived>`                   | List As `String</api/data_types/string>`                                                                                                           |         |
| `LoginSuccessful<pop3socket.loginsuccessful>`             |                                                                                                                                                    |         |
| `MessageCount<pop3socket.messagecount>`                   | Count As `Integer</api/data_types/integer>`                                                                                                        |         |
| `MessageDeleted<pop3socket.messagedeleted>`               | Index As `Integer</api/data_types/integer>`                                                                                                        |         |
| `MessageReceived<pop3socket.messagereceived>`             | Index As `Integer</api/data_types/integer>`, Message As `EmailMessage</api/networking/emailmessage>`                                               |         |
| `RollbackSuccessful<pop3socket.rollbacksuccessful>`       |                                                                                                                                                    |         |
| `SendComplete<pop3socket.sendcomplete>`                   | UserAborted As `Boolean</api/data_types/boolean>`                                                                                                  |         |
| `SendProgress<pop3socket.sendprogress>`                   | BytesSent As `Integer</api/data_types/integer>`, BytesLeft As `Integer</api/data_types/integer>`                                                   |         |
| `ServerAvailable<pop3socket.serveravailable>`             |                                                                                                                                                    |         |
| `ServerCommandReply<pop3socket.servercommandreply>`       | Command As `String</api/data_types/string>`, Data As `String</api/data_types/string>`                                                              |         |
| `ServerError<pop3socket.servererror>`                     | ErrorCode As `Integer</api/data_types/integer>`, ErrorMessage As `String</api/data_types/string>`, MessageID As `Integer</api/data_types/integer>` |         |
| `TopLinesReceived<pop3socket.toplinesreceived>`           | Index As `Integer</api/data_types/integer>`, Data As `EmailMessage</api/networking/emailmessage>`                                                  |         |

## Property descriptions

<div id="pop3socket.address">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.Address

**Address** As `String</api/data_types/string>`

The TCP/IP address to try to connect to.

In this example, the address has been entered into a `TextField</api/user_interface/desktop/desktoptextfield>`.

``` xojo
TCPSocket1.Address = TextField1.Text
```

<div id="pop3socket.bytesavailable">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.BytesAvailable

**BytesAvailable** As `Integer</api/data_types/integer>`

The number of bytes of data are available in the internal receive buffer.

This property is read-only.

``` xojo
TextField1.Text = Me.BytesAvailable.ToString
```

<div id="pop3socket.byteslefttosend">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.BytesLeftToSend

**BytesLeftToSend** As `Integer</api/data_types/integer>`

The number of bytes left in the queue remaining to be sent.

This property is read-only.

This enables you to create a synchronous socket without needing to subclass it.

``` xojo
TextField1.Text = Me.BytesLeftToSend.ToString
```

<div id="pop3socket.encryptpassword">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.EncryptPassword

**EncryptPassword** As `Boolean</api/data_types/boolean>`

If `True</api/language/true>`, the password is encrypted when being sent to the mail server.

EncryptPassword uses the APOP protocol to transfer the login and password, as described in RFC 1939. If set to false, the POP3 commands USER and PASS are used instead, i.e. the password is sent in clear.

``` xojo
If Me.Caption = "Connect" Then
  Socket1.Address = NthField(ServerFld.Text, ":", 1)
  Socket1.Port = Val(NthField(ServerFld.Text, ":", 2))
  If socket1.Port = 0 Then
    Socket1.Port = 110
  End If
  Socket1.EncryptPassword = True
  Socket1.Username = UsernameFld.Text
  Socket1.Password = PasswordFld.Text

  ProgressBar1.Maximum = 0
  Socket1.Connect
  Me.Caption = "Disconnect"
Else
  Socket1.DisconnectFromServer
  Me.Caption = "Connect"
End If
```

<div id="pop3socket.handle">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.Handle

**Handle** As `Integer</api/data_types/integer>`

This is the socket's internal descriptor and it can be used with `Declare</api/language/declare>` statements.

This property is read-only.

- On Windows, Handle is a Socket, suitable for use in `Declares</api/language/declare>` on Windows.
- On macOS and Linux, Handle is a UNIX socket descriptor.

The descriptor is platform-specific. If *Handle* is less than zero, the descriptor is not available.

<div id="pop3socket.isconnected">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.IsConnected

**IsConnected** As `Boolean</api/data_types/boolean>`

Indicates whether the socket is currently connected.

This property is read-only.

For `TCPSockets</api/networking/tcpsocket>`, a connection means you can send and receive data and are connected to a remote machine. For `UDPSockets</api/networking/udpsocket>`, this means that you are bound to the port and are able to send, receive, join or leave multicast groups, or set socket options.

``` xojo
If EasyUDPSocket1.IsConnected Then
  ' proceed using the connection
Else
  MessageBox("Connection failed!")
End If
```

<div id="pop3socket.localaddress">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.LocalAddress

**LocalAddress** As `String</api/data_types/string>`

The local IP address of the computer.

This property is read-only.

``` xojo
Var localIP As String = Socket1.LocalAddress
```

<div id="pop3socket.networkinterface">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.NetworkInterface

**NetworkInterface** As `NetworkInterface</api/networking/networkinterface>`

Specifies which network interface the socket should use when binding.

You can get the network interface(s) of the user's computer by calling the `GetNetworkInterface<system.networkinterface>` method of the `System</api/os/system>` module.

Leaving this property set to `Nil</api/language/nil>` will use the currently selected interface. In the case of `UDPSockets</api/networking/udpsocket>`, if you assign a non-`Nil</api/language/nil>` value, the socket may not be able to receive broadcast messages. The behavior is OS-dependent; it appears to work on Windows but not on other supported operating systems. If you wish to send broadcast packets out, then you should not bind to a specific interface because the behavior is undefined.

This example specifies that the `TCPSocket</api/networking/tcpsocket>` will use the first Network Interface on the user's computer.

``` xojo
TCPSocket1.NetworkInterface = System.NetworkInterface(0)
```

<div id="pop3socket.password">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.Password

**Password** As `String</api/data_types/string>`

The password to use for security when connecting to the mail server.

<div id="pop3socket.port">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.Port

**Port** As `Integer</api/data_types/integer>`

The port to bind on or connect to.

On most operating systems, attempting to bind to a port less than 1024 causes a `Error<socketcore.error>` event to fire with an error number 107 unless the application is running with administrative permissions. This is due to security features built into the underlying OS.

You need to set the port property explicitly before any call to Listen or Connect as the Port property will be modified to reflect what the actual bound port is during the various stages of operation.

For instance, if you listen on port 8080 and a connection comes in, you can check the Port property to ensure that you're still listening on port 8080 (that the port hasn't been hijacked). Or, if you connect to a socket on port 8080, once the connection occurs, you can check to see what port the OS has bound you to. This will be a random-seeming port number.

This trick can be very useful when you do things like Listen on port 0. In that case, the OS will pick a port for you and listen on it. Then you can check the Port property to see which port the OS picked. This functionality is used for various protocols, such as FTP.

This example sets the Port to 8080.

``` xojo
TCPSocket1.Port = 8080
```

<div id="pop3socket.remoteaddress">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.RemoteAddress

**RemoteAddress** As `String</api/data_types/string>`

The address of the remote machine you are connected to.

This property is read-only.

Use this instead of the Address property to determine the address of the machine you are actually connected to.

This example reports the address of the remote machine that the user is connected to. It is in the Connected event.

``` xojo
TextField1.Text = Me.RemoteAddress
```

<div id="pop3socket.username">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.Username

**Username** As `String</api/data_types/string>`

The username to use for authentication when connecting to the mail server.

## Method descriptions

<div id="pop3socket.checkserverconnection">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.CheckServerConnection

**CheckServerConnection**

Sends a "NOOP" command to the mail server.

This is a command that asks the server to reply. This can be useful to check that the mail server is still responding and also tells the mail server that you are still connected if there has been no activity for a long period of time.

If successful, the ServerAvailable event handler is called.

In this example, a <span class="title-ref">POP3Socket</span> has been added to the window and named socket1.

``` xojo
socket1.CheckServerConnection
```

<div id="pop3socket.close">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.Close

**Close**

Closes the socket's connection, closes any connections the socket may have, and resets the socket.

The only information that is retained after calling Close is the socket's port, address (in the case of `TCPSockets</api/networking/tcpsocket>`), LastErrorCode properties, and data left in the socket's receive buffer. All other information is discarded.

This example closes the `EasyTCPSockets</api/networking/easytcpsocket>` that were open. The sockets were added to the main window.

``` xojo
Connector.Close
Listener.Close
```

<div id="pop3socket.connect">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.Connect

**Connect**

Connects to the mail server and logs in with the values in the *Username* and *Password*properties.

<div id="pop3socket.countmessages">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.CountMessages

**CountMessages**

Asks the server for the number of messages in the mailbox. It triggers the MessageCount event, from which you can get the total.

This is equivalent to the POP3 **STAT** command.

<div id="pop3socket.deletemessage">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.DeleteMessage

**DeleteMessage**(Index As `Integer</api/data_types/integer>`)

Tells the mail server to delete the specified message.

<div id="pop3socket.disconnect">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.Disconnect

**Disconnect**

Disconnects the socket, resets it, and fires a `SocketCore</api/networking/socketcore>` Error event with a 102 error to let you know that the socket has been disconnected.

This example disconnects the `EasyTCPSockets</api/networking/easytcpsocket>` that were opened.

``` xojo
Connector.Disconnect
Listener.Disconnect
```

<div id="pop3socket.disconnectfromserver">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.DisconnectFromServer

**DisconnectFromServer**

Disconnects from the mail server. This sends a “QUIT” command to the mail server and waits for it to close the connection.

This message logs off from the server. Socket1 is on the layout and has been declared as a <span class="title-ref">POP3Socket</span>.

``` xojo
socket1.DisconnectFromServer
```

<div id="pop3socket.endoffile">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.EndOfFile

**EndOfFile** As `Boolean</api/data_types/boolean>`

Returns `True</api/language/true>` when there's no more data left to read.

This code reads the rows and columns of data from a tab-delimited text file into a `ListBox</api/deprecated/listbox>`:

``` xojo
Var f As FolderItem
Var textInput As TextInputStream
Var rowFromFile, oneCell As String

f = FolderItem.ShowOpenFileDialog("text/plain") ' defined as a FileType
If f <> Nil Then
  textInput = TextInputStream.Open(f)
  textInput.Encoding = Encodings.UTF8

  Do
    rowFromFile = textInput.ReadLine
    Var values() As String = rowFromFile.Split(Chr(9))
    ListBox1.ColumnCount = values.Count
    ListBox1.AddRow("")
    Var col As Integer
    For Each value As String In values
      ListBox1.CellTextAt(ListBox1.LastAddedRowIndex, col) = value
      col = col + 1
    End For
  Loop Until textInput.EndOfFile

  textInput.Close
End If
```

This example reads each pair of bytes from a file and writes them in reverse order to a new file. The user chooses the source file using the Open-file dialog box and saves the new file using the Save as dialog box. The EOF property is used to terminate the `Do...Loop</api/language/loops/do...loop>`.

``` xojo
Var readFile As FolderItem = FolderItem.ShowOpenFileDialog("text")
If readFile <> Nil Then
  Var ReadStream As BinaryStream = BinaryStream.Open(readFile, False)
  ReadStream.LittleEndian = True
  Var writeFile As FolderItem = FolderItem.ShowSaveFileDialog("", "")
  If writeFile <> Nil Then
    Var writeStream As BinaryStream = BinaryStream.Create(writeFile, True)
    writeStream.LittleEndian = True
    Do Until ReadStream.EndOfFile
      writeStream.WriteInt8(ReadStream.ReadInt8)
    Loop
    writeStream = Nil
  End If
  readStream = Nil
End If
```

<div id="pop3socket.flush">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.Flush

**Flush**

Immediately sends the contents of internal write buffers to disk or to the output stream.

This function can be useful in point-to-point communication over sockets and similar connections: To optimize for transmission performance, some types of output streams try to collect small pieces of written data into one larger piece for sending instead of sending each piece out individually. By calling Flush, the data collection is stopped and the data is sent without further delay, reducing latency.

When using this on a stream that ends up as a file on disk, it is useful, too: Any short parts of previously written data are written to disk right away, ensuring the data is actually on disk if the application terminates abruptly, e.g. due to a crash.

Avoid calling this method too often. For example, do not call it between successive Write calls because you'll slow down performance without getting much benefit.

A typical use case would look like this:

``` xojo
mySocket.Write("you typed: ")
mySocket.Write(key)
mySocket.Write(".")
mySocket.Flush
```

<div id="pop3socket.listen">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.Listen

**Listen**

Attempts to listen for incoming connections on the currently specified port.

After calling Listen, the Port property will report the actual port you are bound to.

<div id="pop3socket.listmessages">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.ListMessages

**ListMessages**(\[Index As `Integer</api/data_types/integer>`\])

Requests a message listing. It fires the ListReceived event. It calls the ListReceived event handler.

This list consists of the message index and the size of the message. If no index is passed, it gets the entire list from the server. If a specific index is passed, it will return just the *index* message and size of the message.

This is equivalent to the POP3 **LIST** command.

``` xojo
Me.ListMessages
```

<div id="pop3socket.lookahead">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.Lookahead

**Lookahead**(\[Encoding As `TextEncoding</api/text/encoding_text/textencoding>`\]) As `String</api/data_types/string>`

Returns a `String</api/data_types/string>`, containing the data that is available in the internal queue without removing it.

The optional *Encoding* parameter enables you to specify the text encoding of the data to be returned. The default is `Nil</api/language/nil>`. Use the `Encodings</api/text/encoding_text/encodings>` module to specify an encoding.

This example adds the contents of the internal queue to a `TextArea</api/deprecated/textarea>`. The Listener `EasyTCPSocket</api/networking/easytcpsocket>` has been added to the window.

``` xojo
TextArea1.AddText(listener.Lookahead)
```

<div id="pop3socket.poll">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.Poll

**Poll**

Polls the socket manually, which allows a socket to be used synchronously.

The `EasyTCPSocket</api/networking/easytcpsocket>` "Listener" has been added to the window.

``` xojo
Listener.Poll
```

<div id="pop3socket.purge">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.Purge

**Purge**

Removes all data from the socket's internal receive buffer. It does not affect the socket's internal send buffer.

``` xojo
Listener.Purge
```

<div id="pop3socket.read">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.Read

**Read**(Count As `Integer</api/data_types/integer>`, \[Enc As `TextEncoding</api/text/encoding_text/textencoding>`\]) As `String</api/data_types/string>`

Reads *Count* bytes from the input stream and returns a `String</api/data_types/string>`.

If provided, the optional parameter *Enc* specifies the text encoding to be defined for the `String</api/data_types/string>` to be read.

If *Count* is higher than the amount of bytes currently available in the stream, all available bytes will be returned. Therefore, make sure to always consider the case that you get less than you requested. To see if you received all requested bytes, check the returned string's `String<string.bytes>` property (avoid using `Length<binarystream.length>` as it may give a different number if the encoding is not nil).

If not enough memory is available, you get back an empty string.

This example reads the first 1000 bytes from a `BinaryStream</api/files/binarystream>`.

``` xojo
Var readFile As FolderItem = FolderItem.ShowOpenFileDialog("text/plain")
If readFile <> Nil Then
  Var ReadStream As BinaryStream = BinaryStream.Open(readFile, False)
  ReadStream.LittleEndian = True
  TextArea1.Text = ReadStream.Read(1000, Encodings.UTF8)
End If
```

<div id="pop3socket.readall">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.ReadAll

**ReadAll**(\[Encoding As `TextEncoding</api/text/encoding_text/textencoding>`\]) As `String</api/data_types/string>`

Reads all the data from the internal buffer.

This example reads all the data in the buffer into a `TextArea</api/deprecated/textarea>`.

``` xojo
TextField1.AddText(listener.ReadAll)
```

<div id="pop3socket.retrievelines">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.RetrieveLines

**RetrieveLines**(Index As `Integer</api/data_types/integer>`, LineCount As `Integer</api/data_types/integer>`)

Returns the specified number of lines of a message.

The mail server will return the first *LineCount* of lines that exist in the message you are requesting via the *Index* parameter. If *LineCount* is zero, then the mail server returns only the headers for the message.

This is equivalent to the POP3 **TOP** command.

<div id="pop3socket.retrievemessage">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.RetrieveMessage

**RetrieveMessage**(Index As `Integer</api/data_types/integer>`)

Reads the entire message specified by *Index*.

<div id="pop3socket.rollbackserver">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.RollbackServer

**RollbackServer**

Resets the mail server to the state that it was when you logged in.

RollbackServer can be used to undo deletions that occur by accident. The changes aren't committed until the connection is closed. RollbackServer will roll back changes that have not yet been committed by issuing a RSET command to the POP3 server (see RFC 1939 for more details).

On success, the RollbackSuccessful event is fired. Otherwise, the ServerError event is fired.

``` xojo
Me.RollbackServer
```

<div id="pop3socket.sendservercommand">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.SendServerCommand

**SendServerCommand**(Command As `String</api/data_types/string>`)

Sends the command specified by *Command* to the mail server.

This is useful when you need to send a command that in not supported the <span class="title-ref">POP3Socket</span>.

<div id="pop3socket.write">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.Write

**Write**(Data As `String</api/data_types/string>`)

Writes the passed data to the output stream.

Note that in order to make sure that the data actually ends up on disk or gets sent to the socket it is connected to, the stream must either get closed or the `Flush<writeable.flush>` method be called. Otherwise, the data, if small, may end up temporarily in a write buffer before either a certain time has passed or more data is written. This buffering increases performance when writing lots of small pieces of data, but may be causing unwanted delays when another process, e.g. the other end of a socket connection, is waiting for the data. Consider calling the `Flush<writeable.flush>` method to reduce latencies that this buffering may cause in such cases.

If Write fails, an `IOException</api/exceptions/ioexception>` will be raised.

This example displays the Save As dialog box and writes the contents of the TextArea1 to a text file.

``` xojo
Var f As FolderItem
Var stream As BinaryStream
f = FolderItem.ShowSaveFileDialog(FileTypes1.Text, "Untitled.txt")
If f<> Nil Then
  stream = BinaryStream.Create(f, True)
  stream.Write(TextArea1.Text)
  stream.Close
End If
```

## Event descriptions

<div id="pop3socket.connectionestablished">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.ConnectionEstablished

**ConnectionEstablished**

Occurs when a connection has been established.

If you have provided a username and password, the authentication has not taken place yet when this event fires. All commands which require that the user is authenticated will return an error. In such a case, move your code into the `LoginSuccessful<pop3socket.loginsuccessful>` event.

<div id="pop3socket.disconnected">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.Disconnected

**Disconnected**

Occurs when the connection with the server has been lost.

<div id="pop3socket.listreceived">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.ListReceived

**ListReceived**(List As `String</api/data_types/string>`)

Executes when the `ListMessages<pop3socket.listmessages>` method is called.

The *List* parameter contains the message listing in the format described in RFC 1939.

A typical list is:

``` xojo
+OK 
1 1253
2 7801
3 534
4 6724
.
```

- "+OK " indicates success
- Each following line consists in the message number, a space and the message size
- The final dot indicates the end of the list
- **NOTE** that the end of line is *normally* CRLF, i.e. `EndOfLine<endofline.windows>`.

The following code parses the *List* and store data as an array of `Pairs</api/language/pair>`:

``` xojo
Dim theList() As Pair ' Will hold the result
Dim tmp() As String ' Temporary table

tmp = Split(list, EndOfLine.Windows) ' Store each line in the temporary table

If tmp.Ubound < 2 Then ' There is no more than 2 lines, i.e. there is nothing between the leading "+OK " and the trailing "."
  ' The list is empty
  Return
Else ' The list is not empty
  ' Walk through the temporary table, avoiding the first and last lines which contain no information
  For i As Integer = 1 To tmp.Ubound - 1
    Dim s As String
    s = tmp(i)
    ' Append a new Pair made of the message number (before the space character) and the message size (after the space character)
    theList.Append(New Pair(Val(NthField(s, " ", 1 )), Val(NthField(s, " ", 2))))
  Next

  ' Now we're ready to process the list
  For i As Integer = 0 To theList.Ubound
    Dim p As Pair
    p = theList(i)

    ' p.Left contains the message number as an integer
    ' p.Right contains the message size as an integer

    ' ... Add your code here
  Next
End If
```

<div id="pop3socket.loginsuccessful">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.LoginSuccessful

**LoginSuccessful**

Executes when the login process initiated by calling the Connect method is complete.

<div id="pop3socket.messagecount">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.MessageCount

**MessageCount**(Count As `Integer</api/data_types/integer>`)

Executes when the mail server replies to a CountMessages call and contains the number of messages in the mailbox.

<div id="pop3socket.messagedeleted">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.MessageDeleted

**MessageDeleted**(Index As `Integer</api/data_types/integer>`)

Executes when the mail server replies to a DeleteMessage call and contains the index number of the deleted message.

<div id="pop3socket.messagereceived">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.MessageReceived

**MessageReceived**(Index As `Integer</api/data_types/integer>`, Message As `EmailMessage</api/networking/emailmessage>`)

Executes when a message has been received from the mail server, in response to a call to RetrieveMessage. *The Index* parameter contains the index number of the retrieved message and the message contents is in *Message*.

<div id="pop3socket.rollbacksuccessful">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.RollbackSuccessful

**RollbackSuccessful**

Executes in response to a call to RollbackServer and indicates that the state of the mailbox has been reset.

<div id="pop3socket.sendcomplete">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.SendComplete

**SendComplete**(UserAborted As `Boolean</api/data_types/boolean>`)

Occurs when a send has completed.

Use this to determine when all your data has been sent. *UserAborted* will be `True</api/language/true>` if the user aborted the send by returning `True</api/language/true>` from the SendProgress event. You can use this information to update different status variables or to inform user about the success or failure of the transfer. If the send was completed, this value is `False</api/language/false>`. UserAborted will always be `False</api/language/false>` for UDP sockets.

<div id="pop3socket.sendprogress">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.SendProgress

**SendProgress**(BytesSent As `Integer</api/data_types/integer>`, BytesLeft As `Integer</api/data_types/integer>`)

Occurs when your network provider queues your data in chunks and is about to send the next chunk.

The parameters indicate the amount of progress that has been made during the send. Returns a `Boolean</api/data_types/boolean>`.

Returning `True</api/language/true>` from this event causes the send to be cancelled. This does not close the socket's connection; it only clears the buffer. After all of the data has been transferred you will get a final SendProgress event followed by a `SendComplete<socketcore.sendcomplete>` event.

*bytesSent* is the number of bytes that were sent in the chunk, not the total number of bytes sent.

<div id="pop3socket.serveravailable">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.ServerAvailable

**ServerAvailable**

Executes when the mail server has replied to a call to CheckServerConnection and indicates that the mail server has replied to the call.

<div id="pop3socket.servercommandreply">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.ServerCommandReply

**ServerCommandReply**(Command As `String</api/data_types/string>`, Data As `String</api/data_types/string>`)

Executes in response to a call to `SendServerCommand<pop3socket.sendservercommand>` and contains the mail server's response to the command passed.

<div id="pop3socket.servererror">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.ServerError

**ServerError**(ErrorCode As `Integer</api/data_types/integer>`, ErrorMessage As `String</api/data_types/string>`, MessageID As `Integer</api/data_types/integer>`)

Executes when a protocol-related error occurs.

The error codes returned in the *ErrorCode* parameter are as follows:

| Value | Description             |
|-------|-------------------------|
| 0     | Unknown Error Message   |
| 1     | Incorrect Password      |
| 2     | IncorrectUsername       |
| 3     | Delete Message Failed   |
| 4     | List Messages Failed    |
| 5     | Retrieve Lines Failed   |
| 6     | Retrieve Message Failed |

<div id="pop3socket.toplinesreceived">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

POP3Socket.TopLinesReceived

**TopLinesReceived**(Index As `Integer</api/data_types/integer>`, Data As `EmailMessage</api/networking/emailmessage>`)

Executes in response to a call to RetrieveLines. The *Index* parameter contains the index number of the partial message being retrieved and *Data* contains the requested lines of the message.

## Notes

If you use a constructor in a subclass of <span class="title-ref">POP3Socket</span>, you must call the Super class's constructor in your subclass's constructor. The subclass will not work unless this is done.

Specifications of POP3 (Post Office Protocol version 3) are provided in RFC 1939.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

### Xojo cloud

To access a POP3 server from web apps running on Xojo Cloud, you will first have to use the `FirewallPort</api/xojocloud/firewallport>` class to open the port used to connect to the POP3 server.

``` xojo
Dim fwp As New XojoCloud.FirewallPort(110, _
  XojoCloud.FirewallPort.Direction.Outgoing)
fwp.Open ' This call is synchronous
If fwp.IsOpen() Then
  ' Do what you need to do
End If
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

### Basic usage

As any socket, the POP3 sockets work asynchronously, i.e. the methods trigger exchange of data from/to the POP3 server and results are provided through the available events. If an error occurred, it is sent through the `ServerError<pop3socket.servererror>` event.

Steps:

1.  Once the object is created, set the address of the POP3 server and the port (110 is the default port for POP3 servers not using SSL)
2.  Set the username and password. You can also set `EncryptPassword<pop3socket.encryptpassword>` to `True</api/language/true>` if the server supports APOP authentication.
3.  Call the `Connect<pop3socket.connect>` method.
4.  In the `LoginSuccessful<pop3socket.loginsuccessful>` event, add the code that you want to execute, e.g.:
5.  Call `ListMessages<pop3socket.listmessages>` to receive the list of messages on the server in the `ListReceived<pop3socket.listreceived>` event
6.  Call `RetrieveMessage<pop3socket.retrievemessage>` to get a message through the `MessageReceived<pop3socket.messagereceived>` event

## Sample code

The following example is from the "Email Example" project. The project uses two windows. The "demoWindow" window is used to receive emails. The "sendDemoWindow" window uses the `SMTPSecureSocket</api/networking/smtpsecuresocket>` to send emails.

DemoWindow contains fields for entering the server address, username, and password, a `PushButton</api/deprecated/pushbutton>`, and a `ListBox</api/deprecated/listbox>` for displaying the list of messages. A <span class="title-ref">POP3Socket</span> control, POP3Socket1, has been added to the window. The user clicks the “Connect” `PushButton</api/deprecated/pushbutton>` to connect to the mail server, receive email, and list the messages in a `ListBox</api/deprecated/listbox>`. Its `Action<pushbutton.action>` event establishes a connection to a POP3 server. It gets the name of the server, username, and password from the contents of the `TextFields</api/deprecated/textfield>`, ServerFld, UserNameFld, and PasswordFld.

``` xojo
If Me.Caption = "Connect" Then
  Socket1.address = NthField(ServerFld.Text, ":", 1)
  Socket1.Port = Val(NthField(ServerFld.Text, ":", 2))
  If Socket1.Port = 0 Then
    Socket1.Port = 110
  End If

  Socket1.Username = UsernameFld.Text
  Socket1.Password = PasswordFld.Text

  ProgressBar1.Maximum = 0
  Socket1.Connect
  Me.Caption = "Disconnect"
Else
  Socket1.DisconnectFromServer
  Me.Caption = "Connect"
End If
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The following example in the `MessageReceived<pop3socket.messagereceived>` event of the <span class="title-ref">POP3Socket</span> control, displays the message in the multiline `TextArea</api/deprecated/textarea>`, BodyFld.

``` xojo
Sub MessageReceived(ID As Integer, Email As EmailMessage)
  Dim s As String

  ' display the message
  s = Email.bodyHTML
  If s = "" Then
    s = Email.BodyPlainText
  End If
  BodyFld.Text = ReplaceAll(s, Chr(13) + Chr(10), Chr(13))
End Sub
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The `LoginSuccessful<pop3socket.loginsuccessful>` event executes the `CountMessages<pop3socket.countmessages>` method that's used to determine whether all the messages have been received.

``` xojo
Me.CountMessages
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The <span class="title-ref">POP3Socket</span>'s `TopLinesReceived<pop3socket.toplinesreceived>` event populates the `ListBox</api/deprecated/listbox>` with summary information on each email that was received.

``` xojo
Sub TopLinesReceived(ID As Integer, Email As EmailMessage)
  ' headers received.  populate the Listbox
  ListBox1.AddRow(Email.Subject)
  ListBox1.Cell(ListBox1.LastIndex, 1) = Email.FromAddress
  ListBox1.Cell(ListBox1.LastIndex, 2) = Str(ID)

  If ID < MessageTotal Then ' there are still messages left
    Me.RetrieveLines(id + 1, 0) ' get the next message headers
  End If
End Sub
```

## Compatibility

All project types on all supported operating systems.

## See also

`TCPSocket</api/networking/tcpsocket>` parent class; \* `EmailMessage</api/networking/emailmessage>`, `POP3SecureSocket</api/networking/pop3securesocket>`, `URLConnection</api/networking/urlconnection>`, `SMTPSecureSocket</api/networking/smtpsecuresocket>`, `SocketCore</api/networking/socketcore>`, `TCPSocket</api/networking/tcpsocket>` classes. \* Specifications of POP3 (Post Office Protocol version 3): RFC 1939 and updates.
