我使用mailcore来发送使用访问令牌的邮件..在这里我得到这个错误了好几天。它的工作密码但是当我使用访问令牌时它不起作用。我已经改变了端口和连接类型的每个组合,但仍然遇到了同样的问题。我需要一些帮助。
MCOSMTPSession * smtpSession = [[MCOSMTPSession alloc] init];
smtpSession.hostname = @"smtp.gmail.com";
smtpSession.port = 465;
smtpSession.username = user; //saved value
smtpSession.connectionType = MCOConnectionTypeTLS;
smtpSession.OAuth2Token = token; //saved value(Validated)
smtpSession.authType = MCOAuthTypeXOAuth2;
smtpSession.checkCertificateEnabled=NO;
MCOMessageBuilder * builder = [[MCOMessageBuilder alloc] init];
MCOAddress *fromAdress=[[MCOAddress alloc]init];
fromAdress = [MCOAddress addressWithMailbox:user];
MCOAddress *toAdress=[[MCOAddress alloc]init];
toAdress = [MCOAddress addressWithMailbox:self.to.text];
[[builder header] setFrom:fromAdress];
[[builder header] setTo:@[toAdress]];
NSString *htmlbody1=@"Body";
[[builder header] setSubject:@"Some_subject"];
[builder setHTMLBody:htmlbody1];
[smtpSession setConnectionLogger:^(void * connectionID, MCOConnectionLogType type, NSData * data) {
NSString *response = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"Response %@",response);
}];
NSData * rfc822Data = [builder data];
MCOSMTPSendOperation *sendOperation = [smtpSession sendOperationWithData:rfc822Data];
[sendOperation start:^(NSError *error) {
if(error) {
NSLog(@"Error sending email: %@", error);
} else {
}
}];
我得到了这个回应 回复535-5.7.8不接受用户名和密码。了解更多信息 535 5.7.8 https://support.google.com/mail/answer/14257 gg7sm1578291wjd.10 并得到这个错误 错误域= MCOErrorDomain代码= 5"无法使用当前会话的凭据进行身份验证。