【问题标题】:Unable to send email with IIS7无法使用 IIS7 发送电子邮件
【发布时间】:2017-01-17 00:44:30
【问题描述】:

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

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

SMTP 虚拟服务器使用标准设置进行设置。
有问题的网站使用 4.0 框架,集成应用程序池,我尝试了 ApplicationPoolIdentity 和 NetworkService,但没有任何效果。对于站点的 SMTP 模块,我尝试了 127.0.0.1 的 SMTP 服务器、localhost 和服务器的域名,都在端口 25 上。

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

我一直在尝试从 Internet 上复制的非常基本的脚本,所有 cmets 都说它可以工作。例如

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

经典 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
%>

我发现一个又一个的例子将这些代码块作为工作示例,我做错了什么?

【问题讨论】:

  • 尝试将地址指向实际的 SMTP 服务器。或者设置正确的delivery method
  • 我所知道的发送电子邮件需要有 mailer_email_add 和密码。
  • 电子邮件并不神奇。它必须去某个地方。询问您的网络管理员您的 SMTP 服务器在哪里。
  • OP 说,For the site's SMTP module I've tried an SMTP server of 127.0.0.1, localhost and the server's domain name, all on port 25. 不......这需要指向一个真正的邮件服务器,例如mail.gmail.com。 IIS SMTP 功能只是一个中继代理。它不会直接向任何收件人发送电子邮件。它只能将邮件中继到真正将邮件发送给收件人的真实邮件服务器。
  • @MrGadget,感谢您对本机 SMTP 的说明。我将如何使用继电器?该站点的旧服务器也使用本地 SMTP,没有引用外部服务。

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


【解决方案1】:

换了一双新的眼睛,我们找到了答案。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-11
    • 2015-09-06
    • 2014-10-22
    • 2011-06-02
    • 2021-04-13
    • 2021-09-12
    • 2013-03-30
    相关资源
    最近更新 更多