0

1.Used the code from this link: Sending email from gmail api not received but shown in sent folder 2. I'm using domino server locally with Domino Designer 9 3. Making sure that I'm able to authorize with Gmail api with my google client id (logout from gmail, run the code which is asking me login again) The modified version of the above code is not working.

What is wrong in my code or setup. Here is full code.

    // Your Client ID can be retrieved from your project in the Google
      // Developer Console, https://console.developers.google.com
   //  function assignval(cl,sc){
        // var CLIENT_ID = '261056497849-8kj87m3pjmqko8iot7kpdee2htmaf29a.apps.googleusercontent.com';
        //   var CLIENT_ID = cl;
        //var SCOPES = ['https://www.googleapis.com/auth/gmail.readonly'];
        //   var SCOPES = sc;
   //  }

        var CLIENT_ID = '204856067483-0ib90ohcb1itdvho93cf33pc8g83t4lp.apps.googleusercontent.com';

        var SCOPES = ['https://www.googleapis.com/auth/gmail.readonly','https://mail.google.com/','https://www.googleapis.com/auth/gmail.modify','https://www.googleapis.com/auth/gmail.compose','https://www.googleapis.com/auth/gmail.send'];

      /**
       * Check if current user has authorized this application.
       */
        function auth() {
            var config = {
              'client_id': CLIENT_ID,
              'scope': SCOPES
            };
            gapi.auth.authorize(config, function() {
              console.log('login complete');
              console.log(gapi.auth.getToken());
            });
          }

      function checkAuth() {
        gapi.auth.authorize(
          {
            'client_id': CLIENT_ID,
            'scope': SCOPES.join(' '),
            'immediate': true
          }, handleAuthResult);
      }

      /**
       * Handle response from authorization server.
       *
       * @param {Object} authResult Authorization result.
       */
      function handleAuthResult(authResult) {
        var authorizeDiv = document.getElementById('authorize-div');
        if (authResult && !authResult.error) {
          // Hide auth UI, then load client library.
         authorizeDiv.style.display = 'none';
          loadGmailApi();
        } else {
          // Show auth UI, allowing the user to initiate authorization by
          // clicking authorize button.
          authorizeDiv.style.display = 'inline';
        }
      }

      /**
       * Initiate auth flow in response to user clicking authorize button.
       *
       * @param {Event} event Button click event.
       */
      function handleAuthClick(event) {
        gapi.auth.authorize(
          {client_id: CLIENT_ID, scope: SCOPES, immediate: false},
          handleAuthResult);
        return false;
      }

      /**
       * Load Gmail API client library. List labels once client library
       * is loaded.
       */
      function loadGmailApi() {
        gapi.client.load('gmail', 'v1',send());
      }


        function sendMessage(email, callback) {
            //auth();
            gapi.client.load('gmail', 'v1',function(){
                var base64EncodedEmail = btoa(email).replace(/\//g,'_').replace(/\+/g,'-');
                  alert("Message sending" + base64EncodedEmail);
                  var request = gapi.client.gmail.users.messages.send({
                    'userId': 'me',
                    'message': {
                      'raw': base64EncodedEmail
                    }
                  });
                  request.execute(callback);
            });


        }

        function send() {
            var to = 'mohan_gangan@yahoo.com',
             subject = 'Gmail API sendmessage test',
             content = 'send a Gmail using domino server'
             var email ="From: 'me'\r\n"+
                        "To:  "+ to +"\r\n"+
                        "Subject: "+subject+"\r\n"+
                        "\r\n"+
                        content;
            alert("Message sent to Gamil API");
            sendMessage(email, function (response) {
                //console.log("Handed to Gmail API for sending");
                 {console.log(response)}
            });
            alert("Message sent");
        }
Community
  • 1
  • 1
Mohan Gangan
  • 127
  • 11
  • Are you getting any error? please post error details. – SGC Oct 21 '15 at 22:29
  • This is the error code: POST https://content.googleapis.com/gmail/v1/users/me/messages/send?alt=json 400 (OK)zu @ cb=gapi.loaded_0:85n @ cb=gapi.loaded_0:85Cu @ cb=gapi.loaded_0:85(anonymous function) @ cb=gapi.loaded_0:86g @ cb=gapi.loaded_0:55c @ cb=gapi.loaded_0:46 GmailJscrip:147 Object {code: 400, data: Array[1], message: "'raw' RFC822 payload message string or uploading message via /upload/* URL required", error: Object} – Mohan Gangan Oct 22 '15 at 11:46
  • This is error message from console log: POST https://content.googleapis.com/gmail/v1/users/me/messages/send?alt=json 400 (OK)zu @ cb=gapi.loaded_0:85n @ cb=gapi.loaded_0:85Cu @ cb=gapi.loaded_0:85(anonymous function) @ cb=gapi.loaded_0:86g @ cb=gapi.loaded_0:55c @ cb=gapi.loaded_0:46 GmailJscrip:154 Object {code: 400, data: Array[1], message: "'raw' RFC822 payload message string or uploading message via /upload/* URL required", error: Object} – Mohan Gangan Oct 22 '15 at 23:24
  • Found answer on link: http://stackoverflow.com/questions/30590988/failed-sending-mail-through-google-api-with-javascript Thank you. – Mohan Gangan Oct 23 '15 at 15:19

0 Answers0