Currently I am working on Chrome extension I want particular email (i.e message_id=1543c2a6347d984c) attachment data. I got email message_id also get attachment file name (i.e abc.zip) but how to get that attachment and send back to my server using Ajax.
function getAttachments(userId, message, callback) {
var parts = message.payload.parts;
for (var i = 0; i < parts.length; i++) {
var part = parts[i];
if (part.filename && part.filename.length > 0) {
var attachId = part.body.attachmentId;
var request = gapi.client.gmail.users.messages.attachments.get({
'id': attachId,
'messageId': message.id,
'userId': userId
});
request.execute(function(attachment) {
callback(part.filename, part.mimeType, attachment);
});
}
}
}
Calling
var userId="[email protected]"
var message_id="1543c2a6347d984d";
getAttachments(userId,message_id,function callback(filename,minetype,attachment){
console.log('File Name is '+filename);
console.log('MimeType is '+minetype);
});
Error : main.js:15 Uncaught TypeError: Cannot read property 'parts' of undefined (function getAttachments line 2)