Sending email via workers with mailjet API

The mailjet api provides curl command:
curl -s \
    -X POST \
    --user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
    https://api.mailjet.com/v3.1/send \
    -H 'Content-Type: application/json' \
    -d '{
      "SandboxMode":"true",
      "Messages":[
        {
          "From":[
            {
              "Email":"pilot@mailjet.com",
              "Name":"Your Mailjet Pilot"
            }
          ],
          "HTMLPart":"<h3>Dear passenger, welcome to Mailjet!</h3><br />May the delivery force be with you!",
          "Subject":"Your email flight plan!",
          "TextPart":"Dear passenger, welcome to Mailjet! May the delivery force be with you!",
          "To":[
            {
              "Email":"passenger@mailjet.com",
              "Name":"Passenger 1"
            }
          ]
        }
      ]
    }'


This is what I'm trying to do in my worker:
async function sendEmailOrLog(env: Bindings, username: string, recipient: string, sender_pre_at: string, subject: string, content: string) {
    // Prepare email
    const response = await fetch('https://api.mailjet.com/v3.1/send', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            Authorization: 'Basic ' + btoa(`${env.MAILJET_API_KEY}:${env.MAIILJET_SECRET_KEY}`),
        },
        body: JSON.stringify({
            SandboxMode: 'false',
            Messages: [
                {
                    From: [
                        {
                            Email: `${sender_pre_at.toLowerCase()}@instructor-ai.com`,
                            Name: `Instructor-AI`,
                        },
                    ],
                    HTMLPart: `<h3>${content}</h3>`,
                    Subject: subject,
                    TextPart: content,
                    To: [
                        {
                            Email: recipient,
                            Name: username,


Am I doing something wrong? I get 400 error
Was this page helpful?