Question

I am trying to use Mailgun to send via the HTTP API as follows:

Python:

def send_simple_message(string):
    return requests.post(
        "https://api.mailgun.net/v2/samples.mailgun.org/messages",
        auth=("api", "my-key"),
        data={"from": "<me@mydomain.com",
              "to": ["to@recipient.com"],
              "subject": "",
              "text": string})

My domain is verified using the CNAME records supplied, and I tried sending a couple of test strings.

Nothing visible happened, at all, from my Python script - didn't appear in sent items (gmail). So I tried manually via Terminal, and got the response: <Response [404]>.

Updating the address to mydomain.com (thanks @kwatford) I get <Response [200]> (success).

However, this was a test email I sent to myself (on a different address). I have not received the message, and it is not in the sent box of me@mydomain.com either. What have I done wrong?

Was it helpful?

Solution

Thanks to @kwatford for identifying the issue, exact solution as follows for anyone else confused by the example:

https://api.mailgun.net/v2/samples.mailgun.org/messages should be replaced by:

https://api.mailgun.net/v2/yourdomain.com/messages.

What I initially tried for a [200] response was simply http://mydomain.com which is incorrect.

Further, I was wrong to expect it to appear in sent items, though it does appear (now that I have the correct POST address!) in cp > logs on mailgun.com

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top