Sample code for 30+ languages & platforms
Swift

Transition from MailMan.MxLookupAll to the Chilkat DNS class

Provides instructions for replacing deprecated MxLookupAll method calls with the Chilkat Dns class.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    let mailman = CkoMailMan()!

    // ...
    // ...

    var emailAddr: String? = "joe@example.com"

    // ------------------------------------------------------------------------
    // The MxLookupAll method is deprecated:

    var sa: CkoStringArray? = mailman.mxLookupAll(emailAddress: emailAddr)
    if mailman.lastMethodSuccess == false {
        print("\(mailman.lastErrorText!)")
        return
    }

    // ...
    // ...

    sa = nil

    // ------------------------------------------------------------------------
    // Do the equivalent using the Chilkat DNS class

    let dns = CkoDns()!

    let json = CkoJsonObject()!

    // This gets all MX domains for an email address.  (Typically one domain.)
    // The preferred domain will be at index 0 (see below).
    success = dns.query(recordType: "MX", domain: emailAddr, answer: json)
    if success == false {
        print("\(dns.lastErrorText!)")
        return
    }

    var i: Int = 0
    var count_i: Int = json.size(ofArray: "answer.mx").intValue
    while i < count_i {
        json.i = i
        var domain: String? = json.string(of: "answer.mx[i].domain")
        print("\(domain!)")
        i = i + 1
    }


}