AWS ses sendemail(...)。不确定的

发布于 2025-01-19 12:27:12 字数 2453 浏览 2 评论 0原文

使用节点 v14.18.1

sesLib 是一个导入。const sesLib = new AWS.SESV2({ ...}) 在其他地方定义

来自 MDN 文档:

then() 方法返回一个 Promise。它最多需要两个参数: Promise 成功和失败情况的回调函数。

我正在使用 AWS SES V2 SDK 中的 SendEmail 功能,并使用 .promise() 方法来测试 To 电子邮件地址字段中的空/空值

原始代码

const sendEmailImpl = (other_params, sesLib) => {
...
const params = { ... };
return sesLib.sendEmail(params).promise();
};

我尝试了以下代码,所有不同的变体,但它们都会导致消息 - Cannot read property 'then' of undefined


const sendEmailImpl = (other_params, sesLib) => {
...
const params = { ... };
return sesLib.sendEmail(params).promise()
    .then((data) => {
      console.log(data)
      resolve(data); // tried with & without resolve statement
  })
  .catch((err) => {
    console.log('error', JSON.stringify(err));
    reject(
      'error', JSON.stringify(err); // tried with & without reject statement
    );
    throw new Exception(...);
  });
};
const sendEmailImpl = async (other_params, sesLib) => {
...
  const params = { ... };
  var sendEmailPromise = await sesLib.sendEmail(params).promise();
  sendEmailPromise.then((ok) => {
    return ok;
  })
  .catch((err) => {
    console.log('error', JSON.stringify(err));
    reject(
      'error', JSON.stringify(err); // tried with & without reject statement
    );
    throw new Exception(...);
  });
};

运行 npm test 和 jest 后,它总是返回以下错误

TypeError: Cannot read property 'then' of undefined
...
sesLib.sendEmail(params).promise()
^
.then((data) => {
...

AWS Doc about Promise
https://aws.amazon.com/blogs /developer/support-for-promises-in-the-sdk/
SES 发送电子邮件 API
https://docs.aws.amazon.com/ses/latest/ APIReference/API_SendEmail.html https://docs.aws。 amazon.com/ses/latest/dg/send-email-concepts-email-format.html

using node v14.18.1

sesLib is an import.const sesLib = new AWS.SESV2({ ...}) is defined elsewhere

From MDN documentation:

The then() method returns a Promise. It takes up to two arguments:
callback functions for the success and failure cases of the Promise.

I am using the SendEmail feature in AWS SES V2 SDK using with .promise() method to test for empty/null values in the To email address field

original code

const sendEmailImpl = (other_params, sesLib) => {
...
const params = { ... };
return sesLib.sendEmail(params).promise();
};

I tried the following code, all different variations but they result in the message - Cannot read property 'then' of undefined


const sendEmailImpl = (other_params, sesLib) => {
...
const params = { ... };
return sesLib.sendEmail(params).promise()
    .then((data) => {
      console.log(data)
      resolve(data); // tried with & without resolve statement
  })
  .catch((err) => {
    console.log('error', JSON.stringify(err));
    reject(
      'error', JSON.stringify(err); // tried with & without reject statement
    );
    throw new Exception(...);
  });
};
const sendEmailImpl = async (other_params, sesLib) => {
...
  const params = { ... };
  var sendEmailPromise = await sesLib.sendEmail(params).promise();
  sendEmailPromise.then((ok) => {
    return ok;
  })
  .catch((err) => {
    console.log('error', JSON.stringify(err));
    reject(
      'error', JSON.stringify(err); // tried with & without reject statement
    );
    throw new Exception(...);
  });
};

After running npm test and jest, it always returns the following error

TypeError: Cannot read property 'then' of undefined
...
sesLib.sendEmail(params).promise()
^
.then((data) => {
...

AWS Doc about promises
https://aws.amazon.com/blogs/developer/support-for-promises-in-the-sdk/
SES SendEmail API
https://docs.aws.amazon.com/ses/latest/APIReference/API_SendEmail.html
https://docs.aws.amazon.com/ses/latest/dg/send-email-concepts-email-format.html

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文