我最近将MailCore2合并到了我的Objective-C项目中,并且它运行得很好.现在,我正在将应用程序中的代码转换为Swift.我已成功将MailCore2 API导入到我的swift项目中,但我没有看到如何将以下工作的Objective-C代码转换为Swift代码的文档(Google搜索,libmailcore.com,github):
MCOSMTPSession *smtpSession = [[MCOSMTPSession alloc] init];
smtpSession.hostname = @"smtp.gmail.com";
smtpSession.port = 465;
smtpSession.username = @"matt@gmail.com";
smtpSession.password = @"password";
smtpSession.authType = MCOAuthTypeSASLPlain;
smtpSession.connectionType = MCOConnectionTypeTLS;
MCOMessageBuilder *builder = [[MCOMessageBuilder alloc] init];
MCOAddress *from = [MCOAddress addressWithDisplayName:@"Matt R"
mailbox:@"matt@gmail.com"];
MCOAddress *to = [MCOAddress addressWithDisplayName:nil
mailbox:@"hoa@gmail.com"];
[[builder header] setFrom:from];
[[builder header] setTo:@[to]];
[[builder header] setSubject:@"My message"];
[builder setHTMLBody:@"This is a test message!"];
NSData * rfc822Data = [builder data];
MCOSMTPSendOperation *sendOperation =
[smtpSession sendOperationWithData:rfc822Data];
[sendOperation start:^(NSError *error) {
if(error) {
NSLog(@"Error sending …Run Code Online (Sandbox Code Playgroud) 我试图从mailcore迁移到mailcore2.以前在mailcore中,获取正文结构就像[msg fetchBodyStructure]msg是CTCoreMessage对象一样简单.
使用mailcore2,事情似乎更复杂.在MCOIMAPSession的获取消息体的文档中,我们有:
MCOIMAPFetchContentOperation * op =
[session fetchMessageAttachmentByUIDOperationWithFolder:@"INBOX"
uid:[message uid]
partID:"1.2"
encoding:[part encoding]];
[op start:^(NSError * error, NSData * partData) {
}];
Run Code Online (Sandbox Code Playgroud)
我完全不知道这1.2应该是指什么.作者将用户引用到RFC 822,RFC 2822和RFC 5322,但没有一个能够直接回答上述问题.
有人可以告诉我一个获取整个邮件正文的简单代码示例吗?
我无法通过MailCore2发送附件.我可以使用MailCore for ios 8吗?能否请你为我提供正确的方法.我想在附件中发送docx,pdf,xls,png和jpeg文件
我尝试使用以下代码从我的公司电子邮件中通过IMAP协议获取邮件:
MCOIMAPSession *session = [[MCOIMAPSession alloc] init];
[session setHostname:@"imap.mymail.com"];
[session setPort:993];
[session setUsername:@"accidbright@mymail.com"];
[session setPassword:@"password"];
[session setConnectionType:MCOConnectionTypeTLS];
MCOIMAPFetchMessagesOperation * fetchOperation = [session fetchMessagesByUIDOperationWithFolder:inboxFolder requestKind:MCOIMAPMessagesRequestKindHeaders uids:searchResult];
[fetchOperation start:^(NSError *error, NSArray *messages, MCOIndexSet *vanished) {
if (error) {
NSLog(@"Fetching all the message subjects error: %@!", error);
} else {
NSLog(@"Fetched all the messages subjects!");
}
}];
Run Code Online (Sandbox Code Playgroud)
我得到错误:
Fetching all the message subjects error: Error Domain=MCOErrorDomain Code=4
"The certificate for this server is invalid." UserInfo=0x7889ab0
{NSLocalizedDescription=The certificate for this server is invalid.}!
Run Code Online (Sandbox Code Playgroud)
我知道,我们的邮件是使用域名证书签名的,因此在域外,它是未经验证的证书.但几乎所有使用邮件(fe …