Xbase++ Requires Chilkat v11.0.0+
Xbase++
IMAP STARTTLS (Explicit TLS/SSL)
The StartTls property is set to force the Connect method to automatically convert an connection to TLS/SSL via the STARTTLS IMAP command.This is also known as "explicit TLS/SSL" as opposed to "implicit TLS/SSL". With implicit TLS/SSL, the IMAP client connects on the well-known IMAP TLS/SSL port 993 and the secure channel is immediately established. With explicit TLS/SSL, the IMAP client connects on the typical non-secure port (143 usually) and the converts the connection via the STARTTLS command.
Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oImap
LOCAL nFetchUids
LOCAL oMessageSet
LOCAL oBundle
LOCAL nHeadersOnly
LOCAL oEmail
LOCAL i
LOCAL nNumEmails
nSuccess := 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oImap := CreateObject("Chilkat.Imap")
// Indicate that STARTTLS should be used to convert
// to a secure TLS/SSL connection:
oImap:StartTls := 1
oImap:Port := 143
// Connect to an IMAP server and convert the connection
// to TLS/SSL via STARTTLS.
nSuccess := oImap:Connect("imap.example.com")
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
RETURN
ENDIF
// The remainder of this example is the same as for
// non-TLS/SSL...
// Login
nSuccess := oImap:Login("myLogin", "myPassword")
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
RETURN
ENDIF
// Select an IMAP mailbox
nSuccess := oImap:SelectMailbox("Inbox")
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
RETURN
ENDIF
// Get the message IDs of all the emails in the mailbox
nFetchUids := 1
oMessageSet := CreateObject("Chilkat.MessageSet")
nSuccess := oImap:QueryMbx("ALL", nFetchUids, oMessageSet)
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
oMessageSet:destroy()
RETURN
ENDIF
// Fetch the emails into a bundle object:
oBundle := CreateObject("Chilkat.EmailBundle")
nHeadersOnly := 0
nSuccess := oImap:FetchMsgSet(nHeadersOnly, oMessageSet, oBundle)
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
oMessageSet:destroy()
oBundle:destroy()
RETURN
ENDIF
// Loop over the bundle and display the FROM and SUBJECT of each.
oEmail := CreateObject("Chilkat.Email")
i := 0
nNumEmails := oBundle:MessageCount
DO WHILE i < nNumEmails
oBundle:EmailAt(i, oEmail)
? oEmail:From
? oEmail:Subject
? "--"
i := i + 1
ENDDO
// Disconnect from the IMAP server.
nSuccess := oImap:Disconnect()
oImap:destroy()
oMessageSet:destroy()
oBundle:destroy()
oEmail:destroy()