# Custom email provider - sending test email not working

**URL:** <https://community.auth0.com/t/custom-email-provider-sending-test-email-not-working/170107>\
**Category:** Get Help\
**Tags:** email-providers, smtp\
**Created:** [January 24, 2025, 2:52pm UTC](https://community.auth0.com/t/custom-email-provider-sending-test-email-not-working/170107 "2025-01-24T14:52:42Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucask](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lucask/32/66248_2.png) [@lucask](https://community.auth0.com/u/lucask)\
**Post date:** [January 24, 2025, 2:52pm UTC](https://community.auth0.com/t/custom-email-provider-sending-test-email-not-working/170107/1 "2025-01-24T14:52:42Z")

</div>

Hi, I wanted to create custom email provider and test it by button named Send test email but I’m getting some error. I want to use Postmark for email sending and I wrote some code like in the docs, but I used Postmark API:

```auto
const { request } = require('undici');

/**
* Handler to be executed while sending an email notification
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {CustomEmailProviderAPI} api - Methods and utilities to help change the behavior of sending a email notification.
*/
exports.onExecuteCustomEmailProvider = async (event, api) => {
  
  const sendEmailRequestBody = {
    From: "testsender@mydomain.com",
    To: event.user.email,
    TemplateId: 1234,
    TemplateModel: {
      user: event.user.email
    }
  };

  try 
  {
    const { statusCode, body } = await request('https://api.postmarkapp.com/email/withTemplate', {
      method: 'POST',
      headers: {
        'X-Postmark-Server-Token': `${event.secrets.PostmarkApiKey}`,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(sendEmailRequestBody),
    });

    if (statusCode === 200) 
    {
      console.log('Email sent successfully');
    } else if (statusCode >= 500) 
    {
      // Retry on server errors
      api.notification.retry(
        `Internal Server Error received from Messaging Proxy. Status code: ${statusCode}.`
      );
      return;
    }

    // Drop the notification if unrecoverable
    api.notification.drop(
      `Something went wrong while sending the email event to Messaging Proxy. Status code: ${statusCode}.`
    );
  } catch(error)
  {
    console.error(`Error sending email: ${error.message}`);
    api.notification.drop(
      `An unexpected error occurred. Error: ${error.message}`
    );
  }

  return;
};

```

Locally I was able to send email like this with curl, so it looks ok. In Auth0 logs after sending test email I can see error message like this:

“Error executing trigger: ACTION\_MALFORMED: Invalid action code”

How to fix it? How to be sure that I configured it correctly?

---

<div class="post-metadata">

**Author:** ![marybeth.hunter](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marybeth.hunter/32/61955_2.png) [@marybeth.hunter](https://community.auth0.com/u/marybeth.hunter)\
**Post date:** [January 24, 2025, 5:50pm UTC](https://community.auth0.com/t/custom-email-provider-sending-test-email-not-working/170107/3 "2025-01-24T17:50:40Z")

</div>

Hi,

Welcome to the Auth0 Community!

Could you kindly add some console logs to this action and use the [Real-time Webtask Logs Extension](https://auth0.com/docs/customize/extensions/real-time-webtask-logs) to see at what point the action is failing?

I don’t see this action in your tenant or any corresponding logs. Are you working on this in a different tenant?

Thanks,

Mary Beth

---

<div class="post-metadata">

**Author:** ![lucask](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lucask/32/66248_2.png) [@lucask](https://community.auth0.com/u/lucask)\
**Post date:** [January 27, 2025, 11:23am UTC](https://community.auth0.com/t/custom-email-provider-sending-test-email-not-working/170107/5 "2025-01-27T11:23:50Z")

</div>

Hi, I’m working on different tenant, I’m part of some team.

I have installed Real-time Webtask Logs Extension but after running this test action (Branding → Email provider → Send test email (button)) there is no logs in that extension. I have added some more logging but the logs in extension are empty.

---

<div class="post-metadata">

**Author:** ![lucask](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lucask/32/66248_2.png) [@lucask](https://community.auth0.com/u/lucask)\
**Post date:** [January 27, 2025, 12:49pm UTC](https://community.auth0.com/t/custom-email-provider-sending-test-email-not-working/170107/6 "2025-01-27T12:49:57Z")

</div>

I did some additional test. I have set up the node js app locally and I have used code like this and it worked:

```auto
const { request } = require('undici');

const sendEmailRequestBody = {
    From: "test@mydomain.com",
    To: "test2@mydomain.com",
    TemplateId: 1234,
    TemplateModel: {
      user: "test user"
    }
  };

SendEmail(sendEmailRequestBody);

async function SendEmail(requestBody) { 
    const { statusCode, body } = await request('https://api.postmarkapp.com/email/withTemplate', {
        method: 'POST',
        headers: {
          'X-Postmark-Server-Token': 'myApiKey',
          'Content-Type': 'application/json',
        },
        body: JSON.stringify(requestBody),
      });

      if (statusCode === 200) 
        {
          console.log('Email sent successfully');
        } else if (statusCode >= 500) 
        {
          console.log('Email sent failed');
        }
}

```

So I have used this code in Auth0 custom email provider script and there it is not working and the result is the same as before: “Error executing trigger: ACTION\_MALFORMED: Invalid action code”.

Custom email provider code:

```auto
const { request } = require('undici');

/**
* Handler to be executed while sending an email notification
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {CustomEmailProviderAPI} api - Methods and utilities to help change the behavior of sending a email notification.
*/
exports.onExecuteCustomEmailProvider = async (event, api) => {
  const sendEmailRequestBody = {
    From: "mysenderemail@mydomain.com",
    To: "myemail@mydomain.com",
    TemplateId: 1234,
    TemplateModel: {
      user: "testuser"
    }
  };

SendEmail(sendEmailRequestBody);
};

async function SendEmail(requestBody) { 
    const { statusCode, body } = await request('https://api.postmarkapp.com/email/withTemplate', {
        method: 'POST',
        headers: {
          'X-Postmark-Server-Token': 'myapikey',
          'Content-Type': 'application/json',
        },
        body: JSON.stringify(requestBody),
      });

      if (statusCode === 200) 
        {
          console.log('Email sent successfully');
        } else if (statusCode >= 500) 
        {
          console.log('Email sent failed');
        }
}

```

I was thinking that maybe it is the button fault (“Send test email”) so I have added new user to my tenant and I tried to send verification email for him and it also didn’t worked and the result is the same like in the scenario with test button:  
“Error executing trigger: ACTION\_MALFORMED: Invalid action code”

---

<div class="post-metadata">

**Author:** ![larsf96](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/larsf96/32/33204_2.png) [@larsf96](https://community.auth0.com/u/larsf96)\
**Post date:** [January 27, 2025, 2:28pm UTC](https://community.auth0.com/t/custom-email-provider-sending-test-email-not-working/170107/7 "2025-01-27T14:28:04Z")

</div>

> [@lucask](#):
>
> `const { request } = require('undici');`

I think your issue belongs to this line where you try to import ‘undici’. Regarding to the Auth0 extensibility page ([Can I require? - Search which node modules you can use in webtask.io](https://auth0-extensions.github.io/canirequire/#)) this is not a supported import so you might switch to another package that is supported.

If you simply require ‘requests’, the code seems to be working without the error that you’ve mentioned.

---

<div class="post-metadata">

**Author:** ![lucask](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lucask/32/66248_2.png) [@lucask](https://community.auth0.com/u/lucask)\
**Post date:** [January 27, 2025, 3:56pm UTC](https://community.auth0.com/t/custom-email-provider-sending-test-email-not-working/170107/8 "2025-01-27T15:56:04Z")

</div>

Thanks! That solved the problem. Now I have used ‘axios’ instead of ‘undici’.

FYI: I have used ‘undici’ because of this example in documentation: [Configure a Custom Email Provider](https://auth0.com/docs/customize/email/configure-a-custom-email-provider#example-custom-email-provider-action)

---

<div class="post-metadata">

**Author:** ![larsf96](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/larsf96/32/33204_2.png) [@larsf96](https://community.auth0.com/u/larsf96)\
**Post date:** [January 27, 2025, 4:50pm UTC](https://community.auth0.com/t/custom-email-provider-sending-test-email-not-working/170107/9 "2025-01-27T16:50:08Z")

</div>

@marybeth.hunter As the docs are no longer open source, could you submit a ticket to change the docs for that?

---

<div class="post-metadata">

**Author:** ![marybeth.hunter](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marybeth.hunter/32/61955_2.png) [@marybeth.hunter](https://community.auth0.com/u/marybeth.hunter)\
**Post date:** [January 28, 2025, 2:43pm UTC](https://community.auth0.com/t/custom-email-provider-sending-test-email-not-working/170107/10 "2025-01-28T14:43:34Z")

</div>

Hi @lucask & @larsf96,

I’m happy to hear that using `axios` has resolved the problem. I have let the docs team know about this.

Thanks,

Mary Beth

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [February 11, 2025, 2:43pm UTC](https://community.auth0.com/t/custom-email-provider-sending-test-email-not-working/170107/11 "2025-02-11T14:43:43Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
