[英]How to fetch body of email using Mail Core2 IOS Swift
我正在構建一個接收電子郵件的應用程序,我獲取了電子郵件的主題,但無法獲取正文電子郵件。 這是我的代碼
let imapsession = MCOIMAPSession()
imapsession.hostname = "xxxx"
imapsession.port = 993
imapsession.username = "xxxx"
imapsession.password = "xxxx"
imapsession.connectionType = MCOConnectionType.TLS
let requestKind : MCOIMAPMessagesRequestKind = MCOIMAPMessagesRequestKind.Headers
let folder : String = "INBOX"
let uids : MCOIndexSet = MCOIndexSet(range: MCORangeMake(1, UINT64_MAX))
let fetchOperation : MCOIMAPFetchMessagesOperation = imapsession.fetchMessagesOperationWithFolder(folder, requestKind: requestKind, uids: uids)
fetchOperation.start { (err, msg, vanished) -> Void in
let msgs = msg as! [MCOIMAPMessage]
print("error from server \(err)")
for i in 0..<msgs.count
{
// Here i want the body of all emails fetched...
if let m = msgs[i].header.subject
{
print("\(i). \(m)")
}
}
}
我也看到了這個答案,但我聽不懂
所以請指導我
試試此代碼,它將對您有所幫助:
var session: MCOIMAPSession = MCOIMAPSession()
session.hostname = "imap.gmail.com"
session.port = 993
session.username = UICKeyChainStore.stringForKey("username")
session.password = UICKeyChainStore.stringForKey("password")
session.connectionType = MCOConnectionTypeTLS
var operation: MCOIMAPFetchContentOperation = session.fetchMessageByUIDOperationWithFolder("INBOX", uid: message.uid)
operation.start({(error: NSError, data: NSData) -> Void in
var messageParser: MCOMessageParser = MCOMessageParser(data: data)
var msgHTMLBody: String = messageParser.htmlBodyRendering()
webView.loadHTMLString(msgHTMLBody, baseURL: nil)
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.