Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Microsoft图形API outlook发送附件_Node.js_Api_Outlook_Microsoft Graph Api - Fatal编程技术网

Node.js Microsoft图形API outlook发送附件

Node.js Microsoft图形API outlook发送附件,node.js,api,outlook,microsoft-graph-api,Node.js,Api,Outlook,Microsoft Graph Api,如何使用Microsoft graph outlook API发送附件?我了解发送附件的一切,直到内容字节。我需要发送的文件是word文档、pdf和jpeg,它是否要求我将文件转换为字节,如果是,我将如何做?我正在使用node.js,我有以下代码: exports.send_mail = async function(req, res, next) { let parms = { title: 'Inbox', active: { inbox: true } }; const

如何使用Microsoft graph outlook API发送附件?我了解发送附件的一切,直到内容字节。我需要发送的文件是word文档、pdf和jpeg,它是否要求我将文件转换为字节,如果是,我将如何做?我正在使用node.js,我有以下代码:

  exports.send_mail = async function(req, res, next) {
    let parms = { title: 'Inbox', active: { inbox: true } };
    const accessToken = await authHelper.getAccessToken(req.cookies, res);
    const userName = req.cookies.graph_user_name;

    if (accessToken && userName) {
      parms.user = userName;

      // Initialize Graph client
      const client = graph.Client.init({
        authProvider: (done) => {
          done(null, accessToken);
        }
      });


      //read test.html
      //so you have to wait for the file to read then send it
      message = fs.readFileSync('views/test.html', 'utf8');

      console.log(rawImage.data.toString('utf8'))

      try {
        mailMess ={
          message:{
            subject: 'This is a test',
            body:{
              ContentType: 'HTML',
              Content: message
            },
            ToRecipients:[
              {
                EmailAddress:{
                  Address: 'name@email.com'
                }
              }
            ],
            "attachments": [
              {
                "@odata.type": "#microsoft.graph.fileAttachment",
                "name": "attachment.jpeg",
                "contentBytes": "not sure what to put here"
              }
            ]
          }
        }
        //sendmail
        const result = await client
        .api('/me/sendmail')
        .version('v1.0')
        .post(mailMess);
        res.status('202')

        parms.messages = result.value;
        res.redirect('/');
      } catch (err) {
        parms.message = 'Error retrieving messages';
        parms.error = { status: `${err.code}: ${err.message}` };
        parms.debug = JSON.stringify(err.body, null, 2);
        res.render('error', parms);
      }

    } else {
      // Redirect to home
      res.redirect('/');
    }
  }

我发现param将文件编码为base64