无法使用IIS7

时间:2017-01-17 00:44:31

标签: asp.net vb.net email iis smtp

我正在将网站从IIS6迁移到IIS7。我有一切正常,但该网站不会发送电子邮件。

我已经确认服务器正在正确处理电子邮件,因为当我将文本文档放入拾取文件夹时它会被传递,但是当我尝试通过代码发送消息时,我会收到错误或者什么都没有。

使用标准设置设置SMTP虚拟服务器 有问题的网站使用4.0 Framework,集成应用程序池,我已经尝试过ApplicationPoolIdentity和NetworkService,但没有效果。对于网站的SMTP模块,我尝试了端口25上的127.0.0.1的SMTP服务器,localhost和服务器的域名。

为了测试我一直在使用VBS和经典的asp发送电子邮件以及asp.net。

我一直在尝试从互联网上复制的非常基本的脚本,其中所有评论都说它有效。例如

vb.net。此代码显示没有错误,但没有发送消息,我在事件查看器中找不到任何内容

Public Shared errorEmailTo As String = System.Configuration.ConfigurationManager.AppSettings("errorEmailTo")
Public Shared errorEmailFrom As String = System.Configuration.ConfigurationManager.AppSettings("errorEmailFrom")

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim email As String = "This is a test email."
    show.Text = "To: " + System.Configuration.ConfigurationManager.AppSettings("errorEmailTo") + "<br/>"
    show.Text += "From: " + System.Configuration.ConfigurationManager.AppSettings("errorEmailFrom") + "<br/>"
    Try
        Helper.SendError(email)
        show.Text += "No Error"
    Catch ex As Exception
        show.Text += "Error: " + ex.Message
    End Try

End Sub

Public Shared Sub SendError(ByVal strBody As String)

    Dim Email As New System.Net.Mail.MailMessage(errorEmailFrom, errorEmailTo)
    Email.Subject = "Error Message"
    Email.Body = strBody
    Dim mailClient As New System.Net.Mail.SmtpClient()
    mailClient.UseDefaultCredentials = True
    mailClient.EnableSsl = False


    Try
        mailClient.Send(Email)
    Catch ex As Exception

    End Try

End Sub

VBS。此代码返回错误“传输无法连接到服务器”。除此之外,我找不到任何新的几乎完全相同的代码块

strSMTPFrom = "donotreply@here.com"
strSMTPTo = "me@here.com"
strSMTPRelay = "localhost"
strTextBody = "Body of your email"
strSubject = "Subject line"


Set oMessage = CreateObject("CDO.Message")
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTPRelay
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
oMessage.Configuration.Fields.Update

oMessage.Subject = strSubject
oMessage.From = strSMTPFrom
oMessage.To = strSMTPTo
oMessage.TextBody = strTextBody

oMessage.Send

Classic ASP提供相同的错误消息。

<%
Dim sch, cdoConfig, cdoMessage
sch = "http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
    .Item(sch & "sendusing") = 2 ' cdoSendUsingPort
    .Item(sch & "smtpserver") = "localhost"
    .Item(sch & "smtpserverport") = 25
    .update
End With
Set cdoMessage = CreateObject("CDO.Message")
With cdoMessage
    Set .Configuration = cdoConfig
    .From = "donotreply@here.com"
    .To = "me@here.com"
    .Subject = "Email test"
    .TextBody = "This is the test body of the email"
    .Send
End With
Set cdoMessage = Nothing
Set cdoConfig = Nothing
%>

我发现示例后面的示例将这些代码块作为工作示例,我做错了什么?

1 个答案:

答案 0 :(得分:0)

带着一双新鲜的眼睛,我们找到了答案。

虚拟SMTP服务器正在侦听端口465(SSL),而不是25个。因此,经过更正,经典ASP和VBS工作,但不是VB.Net。我们创建了一个新的虚拟SMTP服务器,监听端口587.只要VB.Net禁用了SSL,它就能工作。看来新服务器在迁移期间没有收到SSL证书。