-2

I'm currently working on gmail API base on this thread

https://stackoverflow.com/a/31792244/6766279

everything works fine if I just need to compose a new email, but I don't know how to do it if i need to reply. i tried changing the data with threadId, and receives an error, 'Recipient address required.'

/* Send the mail! */
$.ajax({
    type: "POST",
    url: "https://www.googleapis.com/upload/gmail/v1/users/me/messages/send?uploadType=multipart",
    contentType: "message/rfc822",
    beforeSend: function (xhr, settings) {
        xhr.setRequestHeader('Authorization', 'Bearer ' + ACCESS_TOKEN);
    },
    data: {
        raw: mail,
        threadId: thread.id
    },
    success: function (res) {
        resolve(res)
    },
    error: function (error) {
        console.log('ERROR:', error.responseJSON.error.message);
        window.open(`${location.origin}/api/google/rest/verify`, "", "width=500, height=500");
    }
}); 

I really need help.

ankitkanojia
  • 3,072
  • 4
  • 22
  • 35
Eysung
  • 11
  • 3

1 Answers1

1
                /* Send the reply! */ 
                $.ajax({
                    type: "POST",
                    url: "https://www.googleapis.com/gmail/v1/users/me/messages/send",
                    headers: {
                      'Content-Type' : 'application/json',
                      'Authorization': 'Bearer ' + ACCESS_TOKEN,
                    },
                    data: JSON.stringify({
                        raw: btoa(mail).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''),
                        threadId : threadId
                    }),
                    success: function(res){
                         console.log(res)
                    },
                    error: function(error){
                        console.log('ERROR:', error); 
                    }
                });

Solved with this,

Eysung
  • 11
  • 3
  • Hi Eyesung remember to accept your own answer if there are no better answers. Refer to [this page](https://stackoverflow.com/help/self-answer). – Raserhin Jan 31 '20 at 09:01