Sample code for 30+ languages & platforms
Swift

Find the "Sent" IMAP Mailbox

See more IMAP Examples

Find the "Sent" IMAP mailbox. Also finds the Junk and Trash mailboxes..

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()!

    imap.ssl = true
    imap.port = 993
    success = imap.connect(hostname: "imap.yourmailserver.com")
    if success == false {
        print("\(imap.lastErrorText!)")
        return
    }

    // Login or authenticate in some way..
    success = imap.login(login: "your_login", password: "your_password")
    if success == false {
        print("\(imap.lastErrorText!)")
        return
    }

    // Get the list of mailboxes.
    var refName: String? = ""
    var wildcardedMailbox: String? = "*"
    var subscribed: Bool = false

    let mboxes = CkoMailboxes()!
    success = imap.mbxList(subscribed: subscribed, reference: refName, mbxPattern: wildcardedMailbox, mboxes: mboxes)
    if success == false {
        print("\(imap.lastErrorText!)")
        return
    }

    // The mailbox with the "/Sent" flag is the "Sent" mailbox.
    // Likewise for Junk and Trash..
    var i: Int = 0
    while i < mboxes.count.intValue {
        if mboxes.hasFlag(index: i, flagName: "\\Sent") == true {
            print("Sent mailbox: \(mboxes.getName(index: i)!)")
        }

        if mboxes.hasFlag(index: i, flagName: "\\Junk") == true {
            print("Junk mailbox: \(mboxes.getName(index: i)!)")
        }

        if mboxes.hasFlag(index: i, flagName: "\\Trash") == true {
            print("Trash mailbox: \(mboxes.getName(index: i)!)")
        }

        i = i + 1
    }

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

}