Swift Requires Chilkat v11.0.0+
Swift
Read an attached email
See more Email Object Examples
Open forward-as-attachment.eml from the forwarding example. Read the cover note’s subject, then open each attached message and inspect its own headers and attachment count. This works even when the outer message has no ordinary files.
Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
// Assumes Chilkat is unlocked. See Global Unlock Sample.
let wrapper = CkoEmail()!
success = wrapper.loadEml(mimePath: "forward-as-attachment.eml")
if success != true {
print("\(wrapper.lastErrorText!)")
return
}
print("Cover note: \(wrapper.subject!)")
if wrapper.numAttachedMessages.intValue == 0 {
print("No attached messages.")
return
}
let nested = CkoEmail()!
var i: Int = 0
while (i < wrapper.numAttachedMessages.intValue) {
success = wrapper.getAttached(index: i, email: nested)
if success != true {
print("\(wrapper.lastErrorText!)")
return
}
print("Original author: \(nested.from!)")
print("Original subject: \(nested.subject!)")
print("Files on the original: \(nested.numAttachments.intValue)")
i = i + 1
}
}