Xbase++ Requires Chilkat v11.0.0+
Xbase++
Preview POP3 messages and download a complete email
See more Email Object Examples
Read a short preview for each of up to five messages into an EmailBundle, print their subjects, and download the complete first entry into a separate Email. Configure a POP3 account that supports UIDL and TOP. All messages stay on the server.
Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oMail
LOCAL oPreviews
LOCAL oHeader
LOCAL i
LOCAL oEmail
nSuccess := 0
// Assumes Chilkat is unlocked. See Global Unlock Sample.
oMail := CreateObject("Chilkat.MailMan")
oMail:MailHost := "pop.example.com"
oMail:MailPort := 995
oMail:PopSsl := 1
oMail:RequireSslCertVerify := 1
oMail:PopUsername := "MAIL_USER"
oMail:PopPassword := "MAIL_PASSWORD"
oPreviews := CreateObject("Chilkat.EmailBundle")
// Keep the messages and request minimal previews. Range indexes are zero-based and inclusive.
nSuccess := oMail:FetchRange(1, 1, 0, 0, 4, oPreviews)
IF (nSuccess != 1)
? oMail:LastErrorText
oMail:destroy()
oPreviews:destroy()
RETURN
ENDIF
IF (oPreviews:MessageCount == 0)
? "There are no messages to preview."
nSuccess := oMail:Pop3EndSession()
IF (nSuccess != 1)
? oMail:LastErrorText
oMail:destroy()
oPreviews:destroy()
RETURN
ENDIF
oMail:destroy()
oPreviews:destroy()
RETURN
ENDIF
oHeader := CreateObject("Chilkat.Email")
i := 0
DO WHILE (i < oPreviews:MessageCount)
nSuccess := oPreviews:EmailAt(i, oHeader)
IF (nSuccess != 1)
? oPreviews:LastErrorText
oMail:destroy()
oPreviews:destroy()
oHeader:destroy()
RETURN
ENDIF
? oHeader:Uidl + " " + oHeader:Subject
i := i + 1
ENDDO
// A UI could use its selected row here. FetchFull uses the preview's POP3 identity.
nSuccess := oPreviews:EmailAt(0, oHeader)
IF (nSuccess != 1)
? oPreviews:LastErrorText
oMail:destroy()
oPreviews:destroy()
oHeader:destroy()
RETURN
ENDIF
oEmail := CreateObject("Chilkat.Email")
nSuccess := oMail:FetchFull(oHeader, oEmail)
IF (nSuccess != 1)
? oMail:LastErrorText
oMail:destroy()
oPreviews:destroy()
oHeader:destroy()
oEmail:destroy()
RETURN
ENDIF
nSuccess := oMail:Pop3EndSession()
IF (nSuccess != 1)
? oMail:LastErrorText
oMail:destroy()
oPreviews:destroy()
oHeader:destroy()
oEmail:destroy()
RETURN
ENDIF
? "Full message: " + oEmail:Subject + " Files: " + Str(oEmail:NumAttachments)
nSuccess := oEmail:SaveEml("pop-received.eml")
IF (nSuccess != 1)
? oEmail:LastErrorText
oMail:destroy()
oPreviews:destroy()
oHeader:destroy()
oEmail:destroy()
RETURN
ENDIF
? "Saved pop-received.eml."
oMail:destroy()
oPreviews:destroy()
oHeader:destroy()
oEmail:destroy()