SendGrid 如果附件存在,则发送功能无响应

SendGrid No response from send function if attachment exists

问题总结
如果我尝试发送一封添加了附件的电子邮件,我没有得到 Promise resolve 也没有回复,但是,如果我注释掉附件逻辑,我会收到一个错误(我输入了无效的令牌以获得错误),就像我预期的那样。 doc文件的路径是真实的,但是这段代码我改了。

代码无效:

const fs = require('fs');
const sgMail = require('@sendgrid/mail');
(async () => {
    sgMail.setApiKey('SG.XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXXXX');
    const pathToAttachment = 'Path\To\doc\file.doc';
    const attachment = fs.readFileSync(pathToAttachment).toString('base64');
    const msg = {
        to: 'myemail@gmail.com',
        from: 'youremail@gmail.com',
        subject: 'test',
        text: 'test',
        attachments: [
            {
              content: attachment,
              filename: 'file.doc',
              type: 'application/doc',
              disposition: 'attachment'
            }
          ]
    };
    let result = null;
    try {
        result = await sgMail.send(msg);
        console.log('sent!');
    } catch (err) {
        console.error(err.toString());
    }
    console.log(`result: ${result}`);
})();

没有得到任何响应,代码将忽略 'send' 函数之后的任何代码的其余部分。

代码工作:

const fs = require('fs');
const sgMail = require('@sendgrid/mail');
(async () => {
    sgMail.setApiKey('SG.XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXXXX');
    const pathToAttachment = 'Path\To\doc\file.doc';
    const attachment = fs.readFileSync(pathToAttachment).toString('base64');
    const msg = {
        to: 'myemail@gmail.com',
        from: 'youremail@gmail.com',
        subject: 'test',
        text: 'test',
/*         attachments: [
            {
              content: attachment,
              filename: 'file.doc',
              type: 'application/doc',
              disposition: 'attachment'
            }
          ] */
    };
    let result = null;
    try {
        result = await sgMail.send(msg);
        console.log('sent!');
    } catch (err) {
        console.error(err.toString());
    }
    console.log(`result: ${result}`);
})();

代码按预期工作,得到:

Unauthorized (401)
The provided authorization grant is invalid, expired, or revoked
null
null
result: null

技术细节:
"@sendgrid/mail": "^7.4.0"
节点版本:v14.15.1

我在他们的 GitHub 页面上发布了一个关于此的问题:
https://github.com/sendgrid/sendgrid-nodejs/issues/1220

但他们似乎无法产生错误。
以前有其他人遇到过这个问题吗?

当我写信给 SendGrid 开发人员时,他们承认这是他们包中的一个错误,并且会被修复:

"@orassayag Thanks for providing more information. I was able to recreate this issue and it looks like a bug on our end. We will add it to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog. In the meantime I would suggest using node version 12.20.0 and Sendgrid/mail: 7.4.0 as a work around solution for now. Using these versions, I was able to get the error logs to show up when attaching the same file."

问题结束。

here