Sample code for 30+ languages & platforms
Swift

Access Attached Message (Embedded Email)

How to access an email embedded within another email (i.e. an attached message).

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    let email = CkoEmail()!

    // Load an email from a .eml
    success = email.loadEml(mimePath: "embeddedEmail.eml")
    if success == false {
        print("\(email.lastErrorText!)")
        return
    }

    // Display how many attached emails are embedded within
    // this one:
    var numAttached: Int = email.numAttachedMessages.intValue
    print("numAttached = \(numAttached)")

    // Get the 1st attached message.
    let email2 = CkoEmail()!
    success = email.getAttached(index: 0, email: email2)
    if success == true {

        // Display the subject, From, and a header field...
        print("\(email2.subject!)")
        print("\(email2.from!)")
        print("\(email2.getHeaderField(fieldName: "X-SOMETHING")!)")
    }


}