我正在尝试通过Exchange服务器从我的应用发送电子邮件。但是我不断收到“无法使用当前 session 的凭据进行身份验证”。我注释掉了我尝试过的所有内容,如主机名,端口或连接类型。

我能做什么 ?

  MCOSMTPSession *smtpSession = [[MCOSMTPSession alloc] init];
smtpSession.hostname = @"smpt.office365.com";
//smtpSession.hostname = @"smpt.outlook.office365.com";
//smtpSession.port = 587;
smtpSession.port = 25;
smtpSession.username = @"";
smtpSession.password = @"";
smtpSession.authType = MCOAuthTypeSASLPlain;
//smtpSession.connectionType = MCOConnectionTypeTLS;
smtpSession.connectionType = MCOConnectionTypeStartTLS;

MCOMessageBuilder *builder = [[MCOMessageBuilder alloc] init];
MCOAddress *from = [MCOAddress addressWithDisplayName:@""
                                              mailbox:@""];
MCOAddress *to = [MCOAddress addressWithDisplayName:nil
                                            mailbox:@""];
[[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!");
    }
}];

最佳答案

smtpSession.hostname = @"smpt.office365.com"; ^^^^
错别字?应该是smtp吗?

10-07 19:56