如何在mailcore2中获取邮件正文和最后一封电子邮件?
Posted
技术标签:
【中文标题】如何在mailcore2中获取邮件正文和最后一封电子邮件?【英文标题】:How to get message body and last email in mailcore2? 【发布时间】:2019-10-05 16:39:22 【问题描述】:我想在 Swift 4 中接收消息正文和最后收到的电子邮件或未见过的电子邮件。我搜索它,但使用 Objective-C 或任何其他旧语言的每个代码。在 Gmail、雅虎、Outlook 中。
我收到了电子邮件,但我没有成功获取邮件正文,以及收到的最后一条已知邮件。
var uidSet = MCOIndexSet(range: MCORangeMake(1, UINT64_MAX))
var fetchOp: MCOIMAPFetchMessagesOperation? = session.fetchMessagesByUIDOperation(withFolder: "INBOX", requestKind: MCOIMAPMessagesRequestKind.headers, uids: uidSet)
fetchOp?.start( err, msgs, vanished in
//print(msgs)
let msgs = msgs as? [MCOIMAPMessage]
for msgs in msgs!
我收到了收件箱中的所有电子邮件,但我只想要看不见的消息。主要问题是我没有成功获取消息正文。
【问题讨论】:
我成功获取消息正文..现在我只想获取未读或最后一条消息..我通过快速获取消息正文上传我的代码 【参考方案1】: var session = MCOIMAPSession() // Make Global
session.hostname = "imap.gmail.com"
session.port = 993
session.username = "example@gmail.com"
session.password = "**********"
session.connectionType = MCOConnectionType.TLS
let requestKind: MCOIMAPMessagesRequestKind = [.headers, .flags]
var uidSet = MCOIndexSet(range: MCORangeMake(1, UINT64_MAX))
var fetchOp: MCOIMAPFetchMessagesOperation? = session.fetchMessagesByUIDOperation(withFolder: "INBOX", requestKind: MCOIMAPMessagesRequestKind.headers, uids: uidSet)
fetchOp?.start( err, msgs, vanished) -> Void in
//print(msgs)
let msgs = msgs as? [MCOIMAPMessage]
for msgs in msgs!
// THE uid for this email. The uid is unique for one email
let uiid = msgs.uid
useImapFetchContent(uidToFetch: uiid)
func useImapFetchContent(uidToFetch uid: UInt32)
let operation = session.fetchParsedMessageOperation(withFolder: "INBOX", uid: UInt32(uid))
operation?.start( error, messageParser)-> Void in
if error == nil
let returnValue = messageParser!.plainTextBodyRenderingAndStripWhitespace(false)
let subject = messageParser?.header.subject
print(subject)
let from = messageParser?.header.from
print(from)
let to = messageParser?.header.to
print(to)
let msgPlainBody = messageParser?.plainTextBodyRendering()
print("BODY")
print(msgPlainBody)
【讨论】:
这是我的代码,用于通过 MailCore2 在 Swift 中接收来自 gmail 正文的电子邮件。在运行形式中以上是关于如何在mailcore2中获取邮件正文和最后一封电子邮件?的主要内容,如果未能解决你的问题,请参考以下文章
如何获取使用 Mandrill API 发送的最后一封电子邮件