Mailgun API响应,显示为“正常”状态,但未发送电子邮件(沙盒)

时间:2019-06-27 21:19:16

标签: c# mailgun

我已经建立了一个Mailgun帐户并创建了他们提供的示例类。

我已将我的邮件添加为授权电子邮件。当我运行下面的代码时,我的状态为“确定”(或已完成),但未发送邮件。

响应的上下文是“ Mailgun Magnificent API”,我已经尝试了此处提出的所有建议:Unable to send mail via Mailgun over api or smtp 但它们似乎都不是问题。 (我在URL之后尝试使用Messenger)

image

在输出窗口中也存在此异常,但不会导致程序停止。引发异常:mscorlib.dll中的'System.ArgumentException'

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;
}

1 个答案:

答案 0 :(得分:0)

注释此行

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

并在此处添加/ messages

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

已修复