【发布时间】:2016-07-01 22:41:04
【问题描述】:
我正在使用 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.8https://support.google.com/mail/answer/14257gg7sm1578291wjd.10 并得到这个错误 Error Domain=MCOErrorDomain Code=5 "无法使用当前会话的凭据进行身份验证。
【问题讨论】:
-
您需要正确生成oauth2令牌。
-
这是否意味着我们必须在打开会话之前使用 GTMOAuth2Authentication 类来获取最新的访问令牌 - 还是 mailcore 会为我们这样做?
-
你有没有想过这个问题?我不完全了解 OAuth。使用我认为可以给我正确令牌但仍无法发送电子邮件的 GoogleSign。
标签: ios gmail-api smtpclient mailcore2 smtp-auth