我尝试使用Exchange服务器从我的应用发送电子邮件。但我仍然无法通过当前会话的凭据进行身份验证。"我把我尝试的所有东西都注释掉了,作为主机名,端口或连接类型。
我该怎么办?
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!");
}
}];
答案 0 :(得分:2)
smtpSession.hostname = @"smpt.office365.com";
^^^^
错字?它应该是smtp
吗?