我需要在动态生成的电子邮件中附上收据。我无法附上pdf文件,它表示路径无效。
这是我的代码:
public static IRestResponse SendConfirmationEmail(string emailaddress,string subject,string body)
{
RestClient client = new RestClient();
client.BaseUrl = "https://123456";
client.Authenticator = new HttpBasicAuthenticator("api", "key-abcdef12345huj");
RestRequest request = new RestRequest();
request.AddParameter("domain", "abc.com", ParameterType.UrlSegment);
request.Resource = "{domain}/messages";
request.AddParameter("from", "abc <abc@xyz.com>");
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("~/users/Receipts/abc-414.pdf");
request.AddParameter("attachment",attachment);
request.AddParameter("c", emailaddress);
request.AddParameter("to", emailaddress);
request.AddParameter("subject", subject);
request.AddParameter("html", body);
request.Method = Method.POST;
return client.Execute(request);
}
任何人都可以帮我解决这个问题吗?
谢谢
答案 0 :(得分:2)
以这种方式尝试
attachment = new System.Net.Mail.Attachment(HttpContext.Current.Server.MapPath("~/users/Receipts/abc-414.pdf"));
使用Server.MapPath方法返回与Web服务器上指定虚拟路径对应的物理文件路径。
我看到你在POST请求中发送这些参数。你检查了序列化 - 反序列化的过程吗?也许这一步有问题,而且该参数被忽略