POP3Socket
From Xojo Documentation
This item was deprecated in version 2018r4. Please use POP3SecureSocket as a replacement. |
Used to retrieve and manage messages on a POP3 mail server.
Properties | ||||||||||||
|
Methods | ||||||||||||||||||
|
Notes
If you use a constructor in a subclass of POP3Socket, 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 class to open the port used to connect to the POP3 server.
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 event.
|
Examples
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 SMTPSocket to send emails.
DemoWindow contains fields for entering the server address, username, and password, a PushButton, and a ListBox for displaying the list of messages. A POP3Socket control, POP3Socket1, has been added to the window. The user clicks the “Connect” PushButton to connect to the mail server, receive email, and list the messages in a ListBox. Its 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, ServerFld, UserNameFld, and PasswordFld.
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 event of the POP3Socket control, displays the message in the multiline TextArea, BodyFld.
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 event executes the CountMessages method that's used to determine whether all the messages have been received.
The POP3Socket's TopLinesReceived event populates the ListBox with summary information on each email that was received.
// 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
After populating the ListBox, it checks against the window property MessageTotal, which contains the result from a call to CountMessages, to see if there are any more message on the server. MessageTotal is assigned the value of the Count parameter in the MessageCount event.
See Also
- EmailMessage, POP3SecureSocket, HTTPSocket, SMTPSocket, SocketCore, TCPSocket classes.
- Specifications of POP3 (Post Office Protocol version 3): RFC 1939 and updates.