Unable to send mail via Mailgun over api or smtp
Asked Answered
K

5

12

I have setup a new account and not verified my domain. I would like to test and confirm mail-send before proceeding with verification and adding payment information.

I have tried curl using the sandbox method and api key (including smtp). I have also tried to use my domain using the top account mail-address as recipient. But each time the send command (both curl and smtp) I get "Mailgun Magnificent API" response - but no mail is delivered. So far the Mailgun API does not look so Magnificent... I have gone through the documentation multiple times and cannot find what I might be doing wrong..

Any help is much appreciated.

Kirakiran answered 22/7, 2017 at 14:57 Comment(0)
A
28

Faced the same issue while sending emails via api by php curl. I solved it by changing API Base URL https://api.mailgun.net/v3/YOUR_DOMAIN_NAME to https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages. It's because their api is not only for sending. Hope this helps.

Ashmore answered 29/7, 2017 at 16:28 Comment(1)
Apparently they need to move me to a more reputed IP and it seems to work now. Although I had made the mistake to not using 'messages' earlier and that was one of the problems that I had already fixed.Kirakiran
P
12

For anyone else trying to figure out what "Mailgun Magnificent API" means in a Mailgun HTTP 200-OK API response, it occurs when posting to https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/some/api/endpoint when /some/api/endpoint is not a valid Mailgun API endpoint.

If you are using a client library, there's probably a mistake in your Mailgun sender domain setting. Say you've verified the domain mg.example.com with Mailgun. Examples that can result in "Mailgun Magnificent API" (the exact setting name depends on the library):

  • MAILGUN_DOMAIN = mg.example.com # comment—this is a common mistake in dotenv files, which don't usually support inline comments; move the # comment to its own line
  • MAILGUN_DOMAIN = mg.example.com/mysite—get rid of the /mysite part

If you are posting directly to the Mailgun API (or developing a client library), there are some additional ways you might get "Mailgun Magnificent API":

  • Omitting the API endpoint: https://api.mailgun.net/v3/mg.example.com (as noted in another response)
  • Misspelling the endpoint: https://api.mailgun.net/v3/mg.example.com/massages (that should be messages with an e)
  • Including a # or ? after your domain: https://api.mailgun.net/v3/mg.example.com #/messages (see the note above about comments in config files)
  • Including an extra path after your domain: https://api.mailgun.net/v3/mg.example.com/route/to/my/app/messages

Note that you won't see "Mailgun Magnificent API" if YOUR_DOMAIN_NAME is not a valid sending domain you've registered with Mailgun. (In that case, Mailgun instead responds 404-Not Found).

Plausive answered 19/2, 2019 at 21:11 Comment(1)
Thanks a lot. I simply didn't uncomment MAILGUN_DOMAIN and KEY. :-)Lynettelynn
D
1

The mailgun guide shows you to use https://api.mailgun.net/v3/YOUR_DOMAIN as YOUR_DOMAIN_NAME as in the snippet below and this was the problem.

If you're using mailgun-js, you simply need to have YOUR_DOMAIN as YOUR_DOMAIN_NAME.

No need for the https://api.mailgun.net/v3 part

const API_KEY = 'YOUR_API_KEY';
const DOMAIN = 'YOUR_DOMAIN_NAME';
const mailgun = require('mailgun-js')({apiKey: API_KEY, domain: DOMAIN});

const data = {
  from: 'Excited User <[email protected]>',
  to: '[email protected], [email protected]',
  subject: 'Hello',
  text: 'Testing some Mailgun awesomeness!'
};

mailgun.messages().send(data, (error, body) => {
  console.log(body);
});
Diddle answered 14/12, 2020 at 13:35 Comment(0)
I
1

Including an slash "/" after messages url part at the end causes this failure too.

For example if you are using a library like Refit for c#, ensure your service interface be declared like this (see the Post attribute):

public interface IMailgunService
{
    [Post("")]
    Task<JsonDocument> SendEmailAsync([Body(BodySerializationMethod.UrlEncoded)] Dictionary<string, object> data);
}
Immuno answered 17/2, 2022 at 15:32 Comment(0)
B
0

The problem for me was not including my domain name in the url and trying to type everything onto a single line. Strictly following their online example. Typing a backslash will bring your cursor to a new line.

$ curl -s --user 'api:key-xxx' \
https://api.mailgun.net/v3/your_domain/messages \
-F from='User <[email protected]>' \
-F to='[email protected]' \
-F subject='Hello' \
-F text='Testing some mailgun!'

Response

{
  "id": "<xxx.x.xxx@your_domain>",
  "message": "Queued. Thank you."
}
Ban answered 6/2, 2021 at 10:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.