在电子邮件中附加 PDF 文件
本文关键字:PDF 文件 电子邮件 | 更新日期: 2023-09-27 18:32:16
我需要在动态生成的电子邮件中附上收据。我无法附加 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);
}
任何人都可以在这个问题上帮助我吗?
谢谢
尝试这样
attachment = new System.Net.Mail.Attachment(HttpContext.Current.Server.MapPath("~/users/Receipts/abc-414.pdf"));
使用 Server.MapPath 方法返回与 Web 服务器上指定的虚拟路径对应的物理文件路径。
我看到您正在 POST 请求中发送这些参数。您是否检查了序列化-反序列化的过程?也许此步骤有问题,该参数被忽略