下面是我目前在控制台应用程序中运行的代码进行测试。电子邮件已成功发送。
但身体被截断,你只看到没有This is test HTML
的& rest of message
。我可以通过替换&
来解决这个问题,但是这不适用于需要在带有查询字符串参数的电子邮件中嵌入urls
的地方。
我试过没有运气的html编码。
var client = new RestSharp.RestClient("https://api.mailgun.net/v3");
client.Authenticator = new RestSharp.HttpBasicAuthenticator("api", "{APIKEY}");
RestSharp.IRestRequest request = new RestSharp.RestRequest("/{DOMAIN}/messages", RestSharp.Method.POST);
string MailBody = "<html>This is test HTML & rest of message</html>";
request.AddParameter("from", "{EmailAddress}");
request.AddParameter("h:Reply-To", "{EmailAddress}");
request.AddParameter("to", "{EmailAddress}");
request.AddParameter("subject", "Mailgun Test New");
request.AddParameter("html", MailBody);
try
{
RestSharp.IRestResponse response = client.Execute(request);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
我替换了&
&
在文本中,它工作。 在链接中,我只保留&按原样运行。
string MailBody = "<html><body>This is test HTML & rest of message. <a href=\"http://www.google.com?a=b&c=d\">Link with querystring</a></body></html>";
问题在于我正在使用的RestSharp版本。我更新了项目以使用最新的,一切都按预期工作。