我在C#中有以下代码,使用ScriptManager从ASP.NET页面调用:
[WebMethod]
public static void testEmail(string FileName)
{
//Asigning a hardcoded value for test
FileName="c:\\Users\\myuser\\Pictures\\mypicture.jpg";
MailMessage message = new MailMessage();
message.From = new MailAddress("originemailaddr@serverx.net");
message.To.Add("detinationmail@servery.net");
message.IsBodyHtml = true;
AlternateView plainView = AlternateView.CreateAlternateViewFromString("This is my plain text content, viewable by those clients that don't support html", null, "text/plain");
AlternateView htmlView = AlternateView.CreateAlternateViewFromString("Here is an embedded image.<img src=cid:companylogo>", null, "text/html");
LinkedResource logo = new LinkedResource(FileName, "image/jpg");
logo.ContentId = "companylogo";
htmlView.LinkedResources.Add(logo);
message.AlternateViews.Add(plainView);
message.AlternateViews.Add(htmlView);
SmtpClient client = new SmtpClient("0.0.0.0", 25);
client.Timeout = 1000;
client.Credentials = CredentialCache.DefaultNetworkCredentials;
client.Send(message);
message.Dispose();
client.Dispose();
}
当我在本地计算机上调试时,代码正常工作。一旦发布,返回500错误(我认为是由于代码试图在服务器上找到该文件,而不是在打开网页的本地计算机中)。我有一些时间试图找到信息,但到目前为止没有运气。有什么建议吗?