2014-10-17 60 views
-1

我无法用mailcore发送MS Exchange电子邮件。 它总是返回一个错误“无法建立与服务器的稳定连接”。 这里是我的代码什么是用mailcore发送Microsoft Exchange电子邮件的主机名

smtpSession.hostname = @"smtp.outlook.office365.co.uk"; 
    smtpSession.username = [currentUser objectForKey:@"email_account"]; 
    smtpSession.password = [currentUser objectForKey:@"email_password"]; 
    smtpSession.port = 25; 
    smtpSession.connectionType = MCOConnectionTypeClear; 

我想这是因为主机名。 有没有人可以告诉我什么是这种情况下MS Exchange的主机名?

回答

0

最后,我发现这里

smtpSession.hostname = @"smtp.office365.com"; 
    smtpSession.username = [currentUser objectForKey:@"email_account"]; 
    smtpSession.password = [currentUser objectForKey:@"email_password"]; 
    smtpSession.port = 25; 
    smtpSession.connectionType = MCOConnectionTypeStartTLS; 
+0

你介意张贴一个完整的例子发送使用mailcore消息? – 2015-01-21 20:20:51

0

回答别人将来参考下面是使用MailCore2一个完整的示例使用的CocoaPods

加入
#import <MailCore/MailCore.h> 

MCOSMTPSession *smtpSession = [[MCOSMTPSession alloc] init]; 
smtpSession.hostname = @"smtp.outlook.office365.com"; 
smtpSession.username = @"[email protected]"; 
smtpSession.password = @"NotMyPass"; 
smtpSession.port = 587; 
smtpSession.connectionType = MCOConnectionTypeStartTLS; 

MCOMessageBuilder * builder = [[MCOMessageBuilder alloc] init]; 
[[builder header] setFrom:[MCOAddress addressWithDisplayName:@"Me" mailbox:@"[email protected]"]]; 
[[builder header] setTo:@[[MCOAddress addressWithDisplayName:@"To you" mailbox:@"[email protected]"]]]; 
[[builder header] setSubject:@"Mailcore test"]; 
[builder setTextBody:@"Message received"]; 
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!"); 
    } 
}]; 
相关问题