发送包含cc param的电子邮件时,我遇到了mailgun的问题。 但是当我执行该方法时,我从cc电子邮件中得到了错误的标题。
这是我的代码
var client = new RestClient
{
BaseUrl = new Uri("https://api.mailgun.net/v3"),
Authenticator = new HttpBasicAuthenticator("api", "secret-key")
};
var request = new RestRequest();
request.AddParameter("to", "email.to@gmail.com");
request.AddParameter("cc", "email.cc@gmail.com");
client.Execute(request)
那么,任何人都可以帮我解决这个问题吗?
这是电子邮件中的信息
这是我从cc电子邮件
获得的答案 0 :(得分:5)
要解决此问题,请您执行以下操作:
答案 1 :(得分:2)
请在代码中添加request.Method = Method.POST;
,因为
根据{{3}}。
你可以尝试这个代码(使用相同的顺序):
RestClient client = new RestClient ();
client.BaseUrl = new Uri ("https://api.mailgun.net/v3");
client.Authenticator =
new HttpBasicAuthenticator ("api",
"YOUR_API_KEY");
RestRequest request = new RestRequest ();
request.AddParameter ("domain", "YOUR_DOMAIN_NAME", ParameterType.UrlSegment);
request.Resource = "{domain}/messages";
request.AddParameter ("from", "Email From <email.from@gmail.com>");
request.AddParameter ("to", "email.to@gmail.com");
request.AddParameter ("cc", "email.cc@gmail.com");
request.AddParameter ("subject", "Email Subject");
request.AddParameter ("text", "Testing some Mailgun awesomness!");
request.AddParameter ("o:tracking", false);
request.Method = Method.POST;
return client.Execute (request);
此致
答案 2 :(得分:0)
您好我无法复制您的问题但是,每当我使用mailgun时,我使用以下代码,它对我来说很好。如果你想尝试一下。
public static IRestResponse SendSimpleMessage(string email)
{
var order = new CustomerOrder();
RestClient client = new RestClient();
client.BaseUrl = new Uri("https://api.mailgun.net/v3");
client.Authenticator =
new HttpBasicAuthenticator("api",
"key-MINE");
RestRequest request = new RestRequest();
request.AddParameter("domain",
"DOMAINHERE.mailgun.org", ParameterType.UrlSegment);
request.Resource = "{domain}/messages";
request.AddParameter("from", "Shop Staff <postmaster@EMAILTHING>");
request.AddParameter("to", email);
request.AddParameter("cc", "Shop Staff <insert email here>");
request.AddParameter("subject", "Your Order has been placed");
request.AddParameter("text", "Thank you for placing an order with our shop, we have just begun processing your order. You will recieve a follow up email when your order is ready for collection");
request.Method = Method.POST;
return client.Execute(request);
}
然后只需用
调用它ResponseModel.SendSimpleMessage(email);
编辑:我在你的代码中看到的唯一问题是它缺乏
request.Method = Method.POST;
POST方法定义如下:“POST方法用于将实体提交到指定的资源,通常会导致服务器上的状态或副作用发生变化”
我希望这会有所帮助