+ -
当前位置:首页 → 问答吧 → IIS7应用程序发送邮件失败

IIS7应用程序发送邮件失败

时间:2011-12-13

来源:互联网

已经装了IIS的邮件服务器,在IIS7下面有一个网站,运行的很正常,可以发送邮件,但是在这个网站的下面再建立一个应用程序,子站点就发送不了邮件了,提示:

邮件发送失败,没有识别提供给安全包的凭证
  at System.Net.NTAuthentication.GetOutgoingBlob(Byte[] incomingBlob, Boolean throwOnError, SecurityStatus& statusCode)
  at System.Net.NTAuthentication.GetOutgoingBlob(String incomingBlob)
  at System.Net.Mail.SmtpNtlmAuthenticationModule.Authenticate(String challenge, NetworkCredential credential, Object sessionCookie, String spn, ChannelBinding channelBindingToken)
  at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
  at System.Net.Mail.SmtpClient.Send(MailMessage message)

以下是发送代码:
C# code

System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration("~/");
SmtpSection cfg = NetSectionGroup.GetSectionGroup(config).MailSettings.Smtp;
            SmtpNetworkElement network = cfg.Network;
            SmtpClient smtp = new SmtpClient(network.Host);
            smtp.Credentials = new System.Net.NetworkCredential(network.UserName, network.Password);
            smtp.Credentials = new System.Net.NetworkCredential();
            MailAddress from = new MailAddress(cfg.From);
            MailMessage message = new MailMessage();
            message.From = from;
            message.To.Add(new MailAddress(config.AppSettings.Settings["MAIL"].Value));
            message.IsBodyHtml = true;
            message.Subject = subject;
            message.Body = body;
            smtp.Send(message);


父站点和子站点代码是一样的(包括这段邮件发送代码),可就是发送不了,IIS7应用程序池用的是各自的,版本为4.0,集成模式,很奇怪,求解答!
另外如果web.config中的connectionStrings的name相同也会报错,必须在子站点的前面加上<clear/>,为什么?IIS7的应用程序和父站点不是互相独立的吗?

作者: BATTLERxANGE   发布时间: 2011-12-13

哦补充以下,子站点的web.config和父站点的是一样的,包括<mailSettings>节点的邮件配置也是,完全一模一样,可是子站点就是发送不了。

作者: BATTLERxANGE   发布时间: 2011-12-13

你都未用本机的Smtp服务

作者: net5354   发布时间: 2011-12-13