如何在使用 Gmail API 发送新邮件后获取邮件 ID

How to get the message id after sending a new message with gmail api?

本文关键字:新邮件 获取 ID API Gmail      更新时间:2023-09-26

如何使用gmail api发送新邮件后获取邮件ID?

function sendMessage(userId, email, callback) {
  var base64EncodedEmail = btoa(email);
  var request = gapi.client.gmail.users.messages.send({
    'userId': userId,
    'message': {
      'raw': base64EncodedEmail
    }
  });
  request.execute(callback);
}

我找到了解决方案:在回调函数中,我们将得到一个参数对象,其中包含有关已发送消息的所有信息,例如 id ,labelId ...等:

 function callback(){
    var idMail=arguments[0].id;
    /*Stored into the dataBase or others operations */
 }