mailgun / mailgun.js

Javascript SDK for Mailgun
https://www.npmjs.com/package/mailgun.js
Apache License 2.0
519 stars 110 forks source link

After adding a custom domain server throws 401 #388

Closed jousi592 closed 11 months ago

jousi592 commented 11 months ago

After adding a custom domain, my server stopped sending the emails and started throwing:

Failed to send email [Error: Unauthorized] {
status: 401,
details: 'Forbidden',
type: 'MailgunAPIError'
}

My function setup is:

const formData = require("form-data");
const Mailgun = require("mailgun.js");
const mailgun = new Mailgun(formData);
const client = mailgun.client({
username: "api",
key: ".....ec-e0e3e911",
});

const domain = "provocateur.ai"
const data = {
from: "welcome@provocateur.ai",
to,
subject,
text,
html
}

// Sending the email
const body = await mailgun.messages.create(domain, data)

Am I adding something incorrectly? I am unsure as to how to format the domain correctly, cause thats pretty much the only thing I changed, except for the API key which I checked that is correct.

Regards, Josef

jousi592 commented 11 months ago

Ok so I figured out that I need to use the url parameter in the mailgun.client setup options and set it to "https://api.eu.mailgun.net" cause I need to use the EU endpoint.

Would have honestly guessed that the API would recognize what endpoint to use automatically.

Either way, this isnt very well explained in the Docs anywhere, so please add it there 👍 @olexandr-mazepa

kopax commented 10 months ago

I solved this problem years ago and I am back here because they still didn't update their doc. Next time I change provider.

DeadcatDev commented 8 months ago

Same here... year by year. No clear info or example for european clients in docs. Loosing another 2h to figure it out.

olexandr-mazepa commented 8 months ago

@kopax @DeadcatDev Hello Hmm, kinda disagree with the statement that docs missing notes about EU configuration: Here is a mention in README: https://github.com/mailgun/mailgun.js?tab=readme-ov-file#setup-client Here is a mention in docs: https://documentation.mailgun.com/en/latest/quickstart-sending.html#send-via-api