I am using Gmail api in Angular 9, After authenticate, when i send email first time its not sending the email, once i refresh the page then only the email sending correctly.
My code snippet, if anything wrong please reply. Thanks in Advance
gapi.load('client:auth2', () => {gapi.client.load('gmail', 'v1', () => { gapi.client.setToken({ access_token: localStorage.getItem('accessToken') }); gapi.client.init({ Key: this.apiKey, discoveryDocs: ['https://www.googleapis.com/discovery/v1/apis/gmail/v1/rest'], client_id: this.clientId, immediate: true, scope:'https://www.googleapis.com/auth/gmail.send' }).then(res => { return gapi.client.gmail.users.messages.send({ userId: this.useremail, resource: { raw:btoa(message).replace(/\+/g, '-').replace(/\//g, '_'), } }).then(res => { var returnbody=JSON.parse(res.body); }); }) }); });