PowerBuilder
PowerBuilder
Fetch All Messages from a POP3 Mailbox
See more POP3 Examples
Demonstrates the Chilkat MailMan.FetchAll method, which retrieves messages from the POP3 mailbox and appends them to an EmailBundle. The arguments are keepOnServer, headersOnly, numBodyLines, and the EmailBundle that receives the emails. This example downloads every message and iterates the bundle, printing each subject.
Background: An
EmailBundle is Chilkat's container for a set of downloaded messages — you read its MessageCount and pull out each Email with EmailAt. The three flags control how much is fetched: keepOnServer leaves copies in the mailbox rather than removing them, headersOnly downloads just the headers for a fast preview, and numBodyLines can fetch a partial body (0 means the whole body). Traditional POP3 clients download and delete; setting keepOnServer to true supports "leave mail on server" behavior.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Mailman
oleobject loo_Bundle
integer n
oleobject loo_Email
integer i
li_Success = 0
// Demonstrates the MailMan.FetchAll method, which retrieves messages from the POP3 mailbox
// and appends them to an EmailBundle. The arguments are keepOnServer, headersOnly,
// numBodyLines, and the EmailBundle that receives the emails.
loo_Mailman = create oleobject
li_rc = loo_Mailman.ConnectToNewObject("Chilkat.MailMan")
if li_rc < 0 then
destroy loo_Mailman
MessageBox("Error","Connecting to COM object failed")
return
end if
// Configure the POP3 server connection.
loo_Mailman.MailHost = "pop.example.com"
loo_Mailman.MailPort = 995
loo_Mailman.PopSsl = 1
loo_Mailman.PopUsername = "user@example.com"
loo_Mailman.PopPassword = "myPassword"
// Fetch all messages, leaving them on the server, with full bodies.
// keepOnServer=1, headersOnly=0 (fetch the entire message).
// Note: numBodyLines only applies when headersOnly is 1 (it sets how many lines of the
// body to include along with the headers). When headersOnly is 0, the entire message
// is fetched and numBodyLines is ignored.
loo_Bundle = create oleobject
li_rc = loo_Bundle.ConnectToNewObject("Chilkat.EmailBundle")
li_Success = loo_Mailman.FetchAll(1,0,0,loo_Bundle)
if li_Success = 0 then
Write-Debug loo_Mailman.LastErrorText
destroy loo_Mailman
destroy loo_Bundle
return
end if
n = loo_Bundle.MessageCount
Write-Debug "Fetched " + string(n) + " messages."
loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
for i = 0 to n - 1
li_Success = loo_Bundle.EmailAt(i,loo_Email)
Write-Debug loo_Email.Subject
next
// Note: Explicitly connecting/authenticating is optional. Chilkat MailMan automatically
// connects and authenticates -- using the property settings above -- whenever a server
// operation requires it. Calling the explicit connect/authenticate methods can still be
// helpful to determine whether a failure occurs while connecting or while authenticating.
destroy loo_Mailman
destroy loo_Bundle
destroy loo_Email