Sample code for 30+ languages & platforms
PowerBuilder

Connecting to GMAIL using IMAP

Demonstrates how to connect to GMAIL using IMAP.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Imap

li_Success = 0

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

loo_Imap = create oleobject
li_rc = loo_Imap.ConnectToNewObject("Chilkat.Imap")
if li_rc < 0 then
    destroy loo_Imap
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// Turn on session logging:
loo_Imap.KeepSessionLog = 1

// Connect to GMail
// Use TLS
loo_Imap.Ssl = 1
loo_Imap.Port = 993
li_Success = loo_Imap.Connect("imap.gmail.com")
if li_Success <> 1 then
    Write-Debug loo_Imap.LastErrorText
    destroy loo_Imap
    return
end if

// Login
// Your login is typically your GMail email address.
li_Success = loo_Imap.Login("username@gmail.com","myPassword")
if li_Success <> 1 then
    Write-Debug loo_Imap.LastErrorText
    destroy loo_Imap
    return
end if

// Select an IMAP mailbox
li_Success = loo_Imap.SelectMailbox("Inbox")
if li_Success <> 1 then
    Write-Debug loo_Imap.LastErrorText
    destroy loo_Imap
    return
end if

// Show the session log.
Write-Debug loo_Imap.SessionLog

// Disconnect from the IMAP server.
li_Success = loo_Imap.Disconnect()


destroy loo_Imap