【发布时间】:2015-10-07 17:42:19
【问题描述】:
我最近将 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 email: %@", error);
} else {
NSLog(@"Successfully sent email!");
}
}];
有谁知道如何使用此 API 在 Swift 中成功发送电子邮件?提前感谢所有回复的人。
【问题讨论】:
标签: objective-c swift api mailcore2 mailcore