首页 > 解决方案 > sendInBlue API:HTTPError:响应代码 403(您被禁止)

问题描述

我正在尝试使用 sendInBlue API 调用发送交易电子邮件。但它显示错误You are Forbidden。卡在上面一段时间了。我已经在那里激活了我的帐户。仍然无法通过此错误。任何帮助将不胜感激。谢谢

错误:

(node:2364) UnhandledPromiseRejectionWarning: HTTPError: Response code 403 (You are Forbidden)
    at EventEmitter.<anonymous> 

sendInBlueApi.js

const axios = require("axios")
    module.exports = axios.create({
      baseURL: "https://api.sendinblue.com/v3",
        headers: { "api-key": xxxxxxxxxxxxxx },
    
    });

邮件程序.js

const apiInstance = require("./sendInBlueApiInstance");

function sendDownloadLink(email, downloadLinkCode, item) {
  const downloadLink = `${process.env.SERVER_URL}/download/${downloadLinkCode}`;

  return sendEmail({
    email,
    subject: `Download ${item.name}`,
    htmlContent: `
      <h1>Thank you for purchasing ${item.name}</h1>

      <a href="${downloadLink}">Download it now</a>
    `,
    textContent: `Thank you for purchasing ${item.name}
Download it now. ${downloadLink}`,
  });
}


function sendEmail({ email, ...options }) {
  const sender = {
    name: "From name",
    email: "cadaverdeath77@gmail.com",
  };

  return apiInstance.post("/smtp/email", {
    sender,
    replyTo: sender,
    to: [{ email }],
    ...options,
  });
}

module.exports = { sendDownloadLink};

服务器.js

const { sendDownloadLink, sendAllDownloadLinks } = require("./mailer")


const downloadLinkMap = new Map()

app.get("/download/:code", (req, res) => {
  const itemId = downloadLinkMap.get(req.params.code)
  if (itemId == null) {
    return res.send("This link has either expired or is invalid")
  }

  const item = items.find(i => i.id === itemId)
  if (item == null) {
    return res.send("This item could not be found")
  }

  downloadLinkMap.delete(req.params.code)
  res.download(`downloads/${item.file}`)
})

app.get("/purchase-success", async (req, res) => {
  const item = items.find(i => i.id === parseInt(req.query.itemId))
  const {
    customer_details: { email },
  } = await stripe.checkout.sessions.retrieve(req.query.sessionId)

  const downloadLinkCode = createDownloadCode(item.id)
  sendDownloadLink(email, downloadLinkCode, item)
  res.redirect(`${process.env.CLIENT_URL}/download-links.html`)
})

标签: node.jssendinblue

解决方案


我的交易账户未激活。我在 SendinBlue 支持上创建了一张票。他们激活了它,问题已经解决。


推荐阅读