SendGrid not working after creating new order

System Information
  • Strapi Version: 4.5.5
  • Operating System: Windows
  • Database: Postgres
  • Node Version: 16.18.0
  • NPM Version: 9.2.0
  • Yarn Version:

I am very new to strapi. Basically I’ve set up a post request to strapi for create an order. Once the order is placed, this will trigger sendgrid to send a confirmation email to the customer. The post request is successful, using email plugin test on the strapi UI successful. Not sure what is wrong here. Hope to get some advice from the community! Thanks!

 email: {
    config: {
      provider: "sendgrid", // For community providers pass the full package name (e.g. provider: 'strapi-provider-email-mandrill')
      providerOptions: {
        apiKey: env("SENDGRID_API_KEY"),
      },
      settings: {
        defaultFrom: "xxxx@hotmail.com",
        defaultReplyTo: "xxxx@hotmail.com",
      },
    },
  },
```config/server.js
module.exports = ({ env }) => ({

  host: env('HOST', '0.0.0.0'),

  port: env.int('PORT', 1337),

  app: {

    keys: env.array("APP_KEYS"),

  },

});

src/api/order/content-types/order/lifecycles.js

module.exports = {
async afterCreate(event) {
// Connected to “Save” button in admin panel
const { result } = event;
console.log(result.ordercart.orderCart);

const cartList = {};

try {
  await strapi.plugins["email"].services.email.send({
    to: `${result.email}`,
    cc: "xxxxxxx@outlook.com",
    from: "xxxxxxxx@hotmail.com", // e.g. single sender verification in SendGrid
    subject: "[CONFIRMATION] YOUR ORDER HAS BEEN PLACED!",
    html: `
    <html>
body { font-family: Arial, sans-serif; color: #11255d; background-color: #f5f5f5; }
  h1 {
    text-align:center;
    color: #11255d;
    margin-top: 50px;
    margin-bottom: 30px;
  }

  table {
    border-collapse: collapse;
    width: 100%;
  }

  th, td {
    border: 1px solid #11255d;
    padding: 10px;
    text-align: left;
  }

  th {
    background-color: #95b3ac;
  }

  .order-details {
    margin-top: 20px;
    margin-bottom: 50px;
  }

  .order-number {
    font-weight: bold;
  }

  .total {
    text-align: right;
    font-weight: bold;
    margin-top: 50px;
    margin-bottom: 50px;
  }

  .contact {
    margin-top: 50px;
  }
</style>

Order Confirmation

Dear ${result.name},

Thank you for placing your order with us! We're excited to contact you regarding your order soon.

Your order number is: ${result.id}

Here's a summary of your order:

${result.ordercart.orderCart .map( (result) => `` ) .join("")}
Image Item Name Quantity Price/Unit Total
product image ${ result.name } ${result.quantity} RM ${result.price.toFixed( 2 )}/${result.unit} RM ${( result.quantity * result.price ).toFixed(2)}

Total estimated cost: RM ${result.amount.toFixed(2)}

If you have any questions about your order, please feel free to reach out to us at teckhongcs@outlook.com

Thank you again for your order!

Best regards,

Teck Hong ColdStorage Team

`, }); } catch (err) { console.log(err); } }, }; ``` ---