首页 > 解决方案 > Mailgun API responding with Ok status but emails are not being sent (Sandbox)

问题描述

I've set up a Mailgun account and created the sample class they provide.

I've added my mail as an authorized email. WHen I run the code below, I get a status of OK (or completed) but mails aren't being sent.

The context of the response is "Mailgun Magnificent API" and I've tryed everything suggested here: Unable to send mail via Mailgun over api or smtp but none of them seem to be the problem. (i tried with messeges after the URL)

image

There's also this exception in the output window, but it doesn't cause the program to stop. Exception thrown: 'System.ArgumentException' in mscorlib.dll

image

public static void Main(string[] args)
{
    var a = SendSimpleMessage();
    Console.WriteLine(a.Content.ToString());
    Console.ReadLine();
}

public static IRestResponse SendSimpleMessage()
{
    RestClient client = new RestClient();
    client.BaseUrl = new Uri("https://api.mailgun.net/v3/sandbox<bla-bla>.mailgun.org");
    client.Authenticator =
        new HttpBasicAuthenticator("api",
            "<api-key>");
    RestRequest request = new RestRequest();
    request.AddParameter("domain", "sandbox<bla-bla>.mailgun.org", ParameterType.UrlSegment);
    request.Resource = "{domain}/messages";
    request.AddParameter("from", "Phil <mailgun@sandbox<bla-bla>.mailgun.org>");
    request.AddParameter("to", "me@gmail.com");
    request.AddParameter("subject", "Hello");
    request.AddParameter("text", "Testing some Mailgun awesomness!");
    request.Method = Method.POST;
    var v = client.Execute(request);
    return v;
}

标签: c#mailgun

解决方案


注释掉这一行

//request.Resource = "{domain}/messages";

并在此处添加 /messages

client.BaseUrl = new Uri("https://api.mailgun.net/v3/sandbox<bla-bla>.mailgun.org/messages");

解决它


推荐阅读