2015-01-13 6 views
2

나는 서비스 계정 및 JWT 인증을 사용하여 이메일을 보내 매우 도움이되지 않는 메시지를 받고 오류 유지하기 위해 노력하고있어 : { code: 500, message: null }는 googleapis '서비스 계정 및 nodejs에서 JWT의 인증 메일을 발송 실패했습니다

이 코드 Failed sending mail through google api in nodejs

message 대신 resource 매개 변수의 키를 변경하는 해결책이있는 것 같지만 제대로 작동하지 않습니다. 이것은 키가 아직도 내가 다음

jwtClient.authorize(function(err, res) { 
    if (err) return console.log('err', err); 

    var email_lines = []; 

    email_lines.push("From: \"Some Name Here\" <[email protected]>"); 
    email_lines.push("To: [email protected]"); 
    email_lines.push('Content-type: text/html;charset=iso-8859-1'); 
    email_lines.push('MIME-Version: 1.0'); 
    email_lines.push("Subject: New future subject here"); 
    email_lines.push(""); 
    email_lines.push("And the body text goes here"); 
    email_lines.push("<b>And the bold text goes here</b>"); 

    var email = email_lines.join("\r\n").trim(); 

    var base64EncodedEmailSafe = new Buffer(email).toString('base64').replace(/\+/g, '-').replace(/\//g, '_'); 

    var params = { 
    auth: jwtClient, 
    userId: "[email protected]", 
    resource: { 
     raw: base64EncodedEmailSafe 
    } 
    }; 

    gmail.users.messages.send(params, function(err, res) { 
    if (err) console.log('error sending mail', err); 
    else console.log('great success', res); 
    }); 
} 

으로 이메일을 보내

var jwtClient = new google.auth.JWT(config.SERVICE_EMAIL, config.SERVICE_KEY_PATH, null, config.ALLOWED_SCOPES); 

으로 인증하고있어 message

주장 때문에 문서 (https://developers.google.com/gmail/api/v1/reference/users/messages/send를)에서 JS 예에서 이상하다 도서관의 논평은 리소스가 올바른 속성이라고도합니다. (https://github.com/google/google-api-nodejs-client/blob/master/apis/gmail/v1.js)

The comments in the library seem to say that resource is the correct property as well 내가 무엇이 누락 되었습니까?

+0

[github에서 문제가 발생했습니다.] (https://github.com/google/google-api-nodejs-client/issues/347) – dthareja

답변

1

는 github에

에 @ryanseys에 따르면 당신은 특정 사용자에게 auth'd 할 필요가 있기 때문에 당신의 OAuth 2.0을 사용합니다 JWT와의 Gmail API 요청 권한을 부여 할 수 없다. 그렇지 않으면 다른 누군가를 사칭하는 메시지를 보내는 것과 같이 정말 그늘진 일을 할 수 있습니다. Google API 탐색기는 OAuth 2.0 인증을 받았기 때문에 작동합니다. 자세한 내용은 https://developers.google.com/gmail/api/auth/about-auth을 참조하십시오.

Failed sending mail through google api in nodejs, auth: OAuth2Client에서 볼 수 있듯이 OAuth2 클라이언트를 사용하여 인증합니다. 현재 특정 Gmail 사용자로 인증하지 않고 Gmail API를 사용하여 메시지를 보낼 수있는 방법은 없습니다. 서비스 계정은 일반 사용자와 동일한 방식으로 Gmail에 액세스 할 수 없습니다.

다른 사람이 서비스 계정을 사용하여 메일을 보내려고합니다.

+0

사용자 상호 작용없이 사용자 이메일을 가져올 수 없다는 말입니다. (사용자가 직접 직접 인증) 심지어 특정 도메인에 대한 모든 관리자 권한을 가지고 있습니다. – Kunok