gpt4 book ai didi

ios - 如何使用 Mail Core2 IOS Swift 获取电子邮件正文

转载 作者:行者123 更新时间:2023-11-29 01:04:02 24 4
gpt4 key购买 nike

我正在构建一个接收电子邮件的应用程序我获取了电子邮件的主题,但无法获取正文电子邮件。这是我的代码

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)")
}
}

我也看到了这个答案,但是我看不懂

Fetch an email body in mailcore2 OSX with swift

所以请指导我这方面

最佳答案

试试这段代码,它会帮助你:

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)
})

关于ios - 如何使用 Mail Core2 IOS Swift 获取电子邮件正文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36643227/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com