Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loImap
LOCAL lnFetchUids
LOCAL loMessageSet
LOCAL loBundle
LOCAL lnHeadersOnly
LOCAL loEmail
LOCAL i
LOCAL lnNumEmails

lnSuccess = 0

* This example assumes the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.

loImap = CreateObject('Chilkat.Imap')

* Indicate that STARTTLS should be used to convert
* to a secure TLS/SSL connection:
loImap.StartTls = 1
loImap.Port = 143

* Connect to an IMAP server and convert the connection
* to TLS/SSL via STARTTLS.
lnSuccess = loImap.Connect("imap.example.com")
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    CANCEL
ENDIF

* The remainder of this example is the same as for 
* non-TLS/SSL...

* Login
lnSuccess = loImap.Login("myLogin","myPassword")
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    CANCEL
ENDIF

* Select an IMAP mailbox
lnSuccess = loImap.SelectMailbox("Inbox")
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    CANCEL
ENDIF

* Get the message IDs of all the emails in the mailbox
lnFetchUids = 1
loMessageSet = CreateObject('Chilkat.MessageSet')
lnSuccess = loImap.QueryMbx("ALL",lnFetchUids,loMessageSet)
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    RELEASE loMessageSet
    CANCEL
ENDIF

* Fetch the emails into a bundle object:
loBundle = CreateObject('Chilkat.EmailBundle')
lnHeadersOnly = 0
lnSuccess = loImap.FetchMsgSet(lnHeadersOnly,loMessageSet,loBundle)
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    RELEASE loMessageSet
    RELEASE loBundle
    CANCEL
ENDIF

* Loop over the bundle and display the FROM and SUBJECT of each.
loEmail = CreateObject('Chilkat.Email')
i = 0
lnNumEmails = loBundle.MessageCount
DO WHILE i < lnNumEmails
    loBundle.EmailAt(i,loEmail)

    ? loEmail.From
    ? loEmail.Subject
    ? "--"
    i = i + 1
ENDDO

* Disconnect from the IMAP server.
lnSuccess = loImap.Disconnect()

RELEASE loImap
RELEASE loMessageSet
RELEASE loBundle
RELEASE loEmail