Swift
Swift
Read Gmail POP3 Mailbox
Reads the header for each email in a GMail POP3 mailbox and displays the FROM and SUBJECT header fields. In your GMail "Forwarding and POP" settings, be sure to select "When messages are accessed with POP keep Gmail's copy in the Inbox".Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// The mailman object is used for receiving (POP3)
// and sending (SMTP) email.
let mailman = CkoMailMan()!
// Set the GMail account POP3 properties.
mailman.mailHost = "pop.gmail.com"
mailman.popUsername = "myLogin"
mailman.popPassword = "myPassword"
mailman.popSsl = true
mailman.mailPort = 995
// Read mail headers and one line of the body.
// To get the full emails, set headersOnly = false
let bundle = CkoEmailBundle()!
var keepOnServer: Bool = true
var headersOnly: Bool = true
var numBodyLines: Int = 1
success = mailman.fetchAll(keepOnServer: keepOnServer, headersOnly: headersOnly, numBodyLines: numBodyLines, bundle: bundle)
if success == false {
print("\(mailman.lastErrorText!)")
return
}
var i: Int = 0
let email = CkoEmail()!
while i < bundle.messageCount.intValue {
bundle.email(at: i, email: email)
// Display the From email address and the subject.
print("From: \(email.from!)")
print("Subject: \(email.subject!)")
i = i + 1
}
}