c# - 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)
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
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;
}
解决方案
注释掉这一行
//request.Resource = "{domain}/messages";
并在此处添加 /messages
client.BaseUrl = new Uri("https://api.mailgun.net/v3/sandbox<bla-bla>.mailgun.org/messages");
解决它
推荐阅读
- for-loop - Scilab - 具有变化索引的 For 循环
- c# - 找不到类型库“Microsoft.Office.Interop.Access.Dao”的包装程序集
- cordova - Cordova 停止从钩子构建
- java - 使用spring esTemplate删除文档中的字段
- python - Scrapy 如何使用 itemloader 填充空项目?
- asp.net-core - 如何在类库项目中使用 AspNetCore 3.0 功能/组件
- html - 应用 type=password 时文本框失去 CSS 样式
- python - 如何调用数组中的所有图像?
- javascript - Eventemitter 循环依赖改进(已关闭)
- python - TypeError: unhashable type: 'dict' for some 50% of the logic where the remaining 50% is working fine