小编iPr*_*mIt的帖子

在Swift中发送Mailcore2普通电子邮件

我最近将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)

api objective-c mailcore mailcore2 swift

12
推荐指数
2
解决办法
9087
查看次数

标签 统计

api ×1

mailcore ×1

mailcore2 ×1

objective-c ×1

swift ×1