400 error. Recipient address required. JavaScript

后端 未结 1 1312
一向
一向 2020-12-22 03:28

I make a simple request step-by-step in Gmail API.

According to all instructions I made this call:

var request = gapi.client.gmail.users.messages.sen         


        
相关标签:
1条回答
  • 2020-12-22 04:08

    The correct format in sending to emails in Gmail API is stated in Users.messages: send:

    function sendMessage(userId, email, callback) {
      // Using the js-base64 library for encoding:
      // https://www.npmjs.com/package/js-base64
      var base64EncodedEmail = Base64.encodeURI(email);
      var request = gapi.client.gmail.users.messages.send({
        'userId': userId,
        'resource': {
          'raw': base64EncodedEmail
        }
      });
      request.execute(callback);
    }
    

    For a more vivid sample on how to use this method, check this SO post:

    [...] the complete message needs to be passed in the raw parameter, see the example:

    From: John Doe <jdoe@machine.example> 
    To: Mary Smith <mary@example.net> 
    Subject: Saying Hello 
    Date: Fri, 21 Nov 1997 09:55:06 -0600 
    Message-ID: <1234@local.machine.example>
    
    This is a message just to say hello. So, "Hello". 
    

    So after base64 encoding the complete message, passing it in the raw parameter without using any other parameter, it works fine.

    0 讨论(0)
提交回复
热议问题