从经典ASP到ASP.NET的代码转换

时间:2011-04-11 15:37:12

标签: c# asp.net iis asp-classic smtp

我的客户在他的专用服务器上有一个经典的ASP站点,他使用IIS发送邮件(它在那里正常工作)。

Set Mail = Server.CreateObject("Persits.MailSender")
Mail.Host = "localhost" ' Specify a valid SMTP server
Mail.Username = "mail@site.com"
Mail.Password = "password"
Mail.From = "info@site.com"

我尝试将此转换为ASP.NET。

SmtpClient smtp = new SmtpClient();
smtp.Host = "localhost";
smtp.Port = 25;
//smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("mail@site.com", "password");

smtp.Send(message);

但这不起作用。它几乎没有任何错误记录器/监控的遗留应用程序,我无法调试在线服务器上的代码。

我的代码出了什么问题?

3 个答案:

答案 0 :(得分:0)

这似乎是权限问题。有关详细信息,请查看此thread

答案 1 :(得分:0)

您可能需要检查端口25是否被阻止,如http://kb.siteground.com/article/How_to_check_whether_SMTP_port_25_is_blocked.html

所示

答案 2 :(得分:0)

如果您使用此方法,请确保本地SMTP服务器正在监控拾取目录:

smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;

如果不是,则消息将保留在那里而不被发送。