PureBasic
PureBasic
Connecting to GMAIL using IMAP
Demonstrates how to connect to GMAIL using IMAP.Chilkat PureBasic Downloads
IncludeFile "CkImap.pb"
Procedure ChilkatExample()
success.i = 0
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
imap.i = CkImap::ckCreate()
If imap.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; Turn on session logging:
CkImap::setCkKeepSessionLog(imap, 1)
; Connect to GMail
; Use TLS
CkImap::setCkSsl(imap, 1)
CkImap::setCkPort(imap, 993)
success = CkImap::ckConnect(imap,"imap.gmail.com")
If success <> 1
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
ProcedureReturn
EndIf
; Login
; Your login is typically your GMail email address.
success = CkImap::ckLogin(imap,"username@gmail.com","myPassword")
If success <> 1
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
ProcedureReturn
EndIf
; Select an IMAP mailbox
success = CkImap::ckSelectMailbox(imap,"Inbox")
If success <> 1
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
ProcedureReturn
EndIf
; Show the session log.
Debug CkImap::ckSessionLog(imap)
; Disconnect from the IMAP server.
success = CkImap::ckDisconnect(imap)
CkImap::ckDispose(imap)
ProcedureReturn
EndProcedure