Postal icon indicating copy to clipboard operation
Postal copied to clipboard

How to fetch email body

Open kushaldexati opened this issue 5 years ago • 1 comments

I am able to fetch message subject but I cannot fetch what's written in thr body of email. Plz help in swift

kushaldexati avatar Jul 03 '20 05:07 kushaldexati

I had some issues, too, but was able to get it to work with the following snippet: (thanks in part to #87)

let postal = Postal(configuration: .init(hostname: "imap.myemailprovider.de", port: 993, login: "[email protected]", password: .plain("mypassword"), connectionType: .tls, checkCertificateEnabled: false))
postal.connect { result in
    switch result {
    case .success:
        postal.fetchLast("INBOX", last: 1, flags: [ .body, .fullHeaders ], onMessage: { message in
                message.body?.allParts.forEach { part in
                    let data = part.data?.decodedData
                    print(String(decoding: data!, as: UTF8.self))
                }
            }, onComplete: { error in
                if let error = error {
                    print("error: \(error)")
                } else {
                    print("done")
                }
        })
    case .failure(let error):
        print("error: \(error)")
    }
}

janek avatar Feb 16 '21 15:02 janek