.net SmtpClient在Web上超时。在.EXE中工作

.net SmtpClient在Web上超时。在.EXE中工作,.net,c#-4.0,smtpclient,.net,C# 4.0,Smtpclient,救命啊 从本地开发机器上的.NET web应用程序发送电子邮件时遇到问题 我有从.NET命令行可执行文件运行的代码。但是,在web应用程序中运行相同的代码总是“超时” 我运行的是64位Windows 7、Windows 7 pro(IIS7)和Visual Studio 2010 我已经关掉了所有的防火墙等 在命令行中工作。在web应用程序的ASPX页面中不工作(发送调用超时) public static void Main(string[] args) { string strSmtp

救命啊

从本地开发机器上的.NET web应用程序发送电子邮件时遇到问题 我有从.NET命令行可执行文件运行的代码。但是,在web应用程序中运行相同的代码总是“超时”

我运行的是64位Windows 7、Windows 7 pro(IIS7)和Visual Studio 2010

我已经关掉了所有的防火墙等

在命令行中工作。在web应用程序的ASPX页面中不工作(发送调用超时)

public static void Main(string[] args)
{
    string strSmtpServer = "theserver";
    string strSmtpUser = "theuser";
    string strSmtpPassword = "thepasswrd";

    SmtpClient client = new SmtpClient( strSmtpServer);
    client.Credentials = new NetworkCredential( strSmtpUser, strSmtpPassword );

    // Specify the e-mail sender.
    MailAddress from = new MailAddress("customersupport@serenitynow.com" );
    // Set destinations for the e-mail message.
    MailAddress to = new MailAddress("iam@serenitynow.com");
    // Specify the message content.
    MailMessage message = new MailMessage(from, to);
    message.IsBodyHtml = true;
    message.Body = "This is a test e-mail <b>message</b> sent by an application. ";


    message.BodyEncoding =  System.Text.Encoding.UTF8;
    message.Subject = "Mail Test!";
    message.SubjectEncoding = System.Text.Encoding.UTF8;

    // Time out exception thrown here on the send call.
    // Waits 60 seconds or so.
    client.Send(message, userState);
    message.Dispose();

}
publicstaticvoidmain(字符串[]args)
{
字符串strSmtpServer=“theserver”;
字符串strSmtpUser=“theuser”;
字符串strsmtpassword=“thepasswrd”;
SmtpClient=新的SmtpClient(strSmtpServer);
client.Credentials=新的网络凭据(strSmtpUser、strsmtpassword);
//指定电子邮件发件人。
MailAddress from=新邮件地址(“customersupport@serenitynow.com" );
//设置电子邮件的目的地。
MailAddress to=新邮件地址(“iam@serenitynow.com");
//指定消息内容。
MailMessage=新的MailMessage(从,到);
message.IsBodyHtml=true;
message.Body=“这是由应用程序发送的测试电子邮件。”;
message.BodyEncoding=System.Text.Encoding.UTF8;
message.Subject=“邮件测试!”;
message.SubjectEncoding=System.Text.Encoding.UTF8;
//发送调用时在此处引发超时异常。
//等待60秒左右。
发送(消息,用户状态);
message.Dispose();
}

这可能是两个不同的问题,包括DNS注册问题和防火墙问题(尽管看起来您已经关闭了它们)

首先,在web计算机上,打开命令提示符并输入“nslookup theserver”,其中服务器与应用程序中使用的值相同。如果您没有IP地址,那么这就是您需要解决的问题

如果您确实获得了IP地址,请尝试ping服务器以查看是否可以从您的计算机访问它。如果不是,那就是要解决的问题

如果SMTP服务器可ping,请尝试使用端口25远程连接到服务器。如果您无法做到这一点,则存在防火墙或其他机制阻止访问

如果这是一个外部SMTP服务器,某些ISP会阻止端口25上的SMTP服务,除非该服务要转到其SMTP服务器

如果可以,并且SMTP服务器支持,我强烈建议切换到端口587或465以避免阻塞问题。这是一个包含更多信息的方便参考资料。

好的,我想出来了。
在IIS中,我更新了应用程序池。开箱即用,它被配置为“ApplicationPoolIdentity”,我将它切换到“LocalSystem”帐户,然后,它就可以工作了。该网页现在可以发送电子邮件。

谢谢。nslookup立即获得正确的ip。命令行程序也可以工作(发送电子邮件)。我认为这可能是一个用户安全问题。我的命令行程序在我的ID(Admin)上运行,但.NET Web应用程序在其他程序下运行。。。