Sample code for 30+ languages & platforms
Swift

Connecting to GMAIL using IMAP

Demonstrates how to connect to GMAIL using IMAP.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

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

    let imap = CkoImap()!

    // Turn on session logging:
    imap.keepSessionLog = true

    // Connect to GMail
    // Use TLS
    imap.ssl = true
    imap.port = 993
    success = imap.connect(hostname: "imap.gmail.com")
    if success != true {
        print("\(imap.lastErrorText!)")
        return
    }

    // Login
    // Your login is typically your GMail email address.
    success = imap.login(login: "username@gmail.com", password: "myPassword")
    if success != true {
        print("\(imap.lastErrorText!)")
        return
    }

    // Select an IMAP mailbox
    success = imap.selectMailbox(mailbox: "Inbox")
    if success != true {
        print("\(imap.lastErrorText!)")
        return
    }

    // Show the session log.
    print("\(imap.sessionLog!)")

    // Disconnect from the IMAP server.
    success = imap.disconnect()

}