Mailgun secret API key rejected

AI-generated summary

Users are reporting an issue with Mailgun’s secret API key being rejected in Discourse due to a format validation error. The error occurs when entering a Mailgun API key, which typically starts with “key-” followed by 32 characters, but the regex validation in Discourse only accepts hexadecimal characters. Several users confirm they are using valid API keys, not SMTP passwords, and note that newer Mailgun keys include dashes, which may not match the current regex. Some users suggest the regex should be less restrictive, as invalid keys would still result in errors during use. A workaround is to generate a new API key with a hex-only format. pfaffman and lunikon discuss the issue, and oxxi notes the problem was resolved after updating the key. Uninen and mshappe confirm the issue persists across multiple versions.

Hi everyone,

I tried to set up Mailgun bounce handling today and therefore wanted to configure the secret Mailgun API key. But I can’t save the key and only get this error message:

Value doesn’t match the required format.

Have they changed their format maybe? My key is “key-” followed by 32 lower-case alpha-numeric characters.

The regex looks fine to me:

And I can’t repro the issue locally using a random key like: key-a64b3021781d9467b6c7e9da7741fed0

The RegEx matches hex values, but my Mailgun key looks more like

^key-[a-z0-9]{32}$

Haven’t tested this regex, just off the top of my head :wink:

Correction: Just saw that my API key even includes dashes (-).

Strange. I just opened a ticket on Mailgun asking if the API key format has changed.

Edit: And I heard back from them. It’s still the same. @lunikon, my best guess is that you’re using an SMTP password rather than an API key. You can look at my install FAQ for how to find the API key.

I am definitely using an API key, from the exact location described in your install FAQ. I guess I’ll have to contact Mailgun myself and figure out what went wrong there. Maybe there was a bug on their side when my set of keys was generated.

I am unable to repro with an actual key from mailgun, feel free to PM me your key if you want me to test it.

I am also seeing this issue on a new install.

ETA: 1.9.0.beta6

And you’re sure that you’re using an API key and not a password?

Very very quite certain :slight_smile:

I’m having the same problem with v2.0.0.beta3. My Mailgun API key also has dashes in it, I assume the regex just doesn’t match. (And yes, I’m definitely using the correct secret key, not a password.)

Nene generate another key?

So apparently this problem does exist for several people over a longer time-span. Wouldn’t it be easier to just make the regex in Discourse less restrictive? The worst that could happen is that someone enters a wrong key, resulting in an error message somewhere. But that could already happen today (with an expired key for example).

I had this problem.
I think older API keys are 32 alpha-numeric, and newer ones are 32 hex characters, and the regex only allows hex. I don’t use the API anywhere else, so I just re-generated my API key so I had a new hex-only one.

I’ve noticed that the keys I’ve seen lately no longer start with “key=”

My current mailgun secret API key gives the error mailgun_api_key: Value doesn't match the required format. I’m on v2.1.0.beta3 +64. Anything I can do to make it accept my API key?

What is the format of your key? Does it start with key-? Are all of the trailing characters in 1234567890abcdef?

Hi, it’s been fixed. Forgot to update this thread. Here’s the link: