首页 > 解决方案 > 在 Windows Server 2008R2 上发送 PEC 时出现问题:传输无法连接到服务器

问题描述

很抱歉关于这个主题的另一个问题,但是在尝试解决这个问题 1 天后(我已经阅读了很多 stackoverflow 答案)我有同样的问题。这是我用于发送 PEC 的遗留代码。一切都很好,直到 12 月,但从那个月起,PEC 服务就不起作用了。

Public Class SslMailSender
    Public Shared Function SendEmail(ByVal Username As String, ByVal Password As String, ByVal MailTo As String, ByVal MailSubject As String, ByVal MailBody As String, ByVal MailFormat As System.Web.Mail.MailFormat, Optional ByVal allegato As String = "", Optional ByVal allegato_2 As String = "") As Boolean
        Try
            Dim sslMail As New System.Web.Mail.MailMessage()
            sslMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", smtps_pec)
            sslMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", smtps_pec_porta)
            sslMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "2") 'Send the message using the network (SMTP over the network)
            sslMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1") 'YES
            sslMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", Username)
            sslMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", Password)
            sslMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true")
            sslMail.From = Username
            sslMail.To = MailTo
            sslMail.Subject = MailSubject
            sslMail.BodyFormat = MailFormat
            sslMail.Body = MailBody
            If allegato <> "" Then
                sslMail.Attachments.Add(New MailAttachment(allegato))
            Else

            End If
            If allegato_2 <> "" Then
                sslMail.Attachments.Add(New MailAttachment(allegato_2))
            Else

            End If


            System.Web.Mail.SmtpMail.SmtpServer = smtps_pec & ":" & smtps_pec_porta
            System.Web.Mail.SmtpMail.Send(sslMail)
            Return True
        Catch ex As Exception
            Using w As StreamWriter = File.AppendText("D:\Temp\log.txt")
                w.Write("\r\nLog Entry : ")
                w.WriteLine($"{DateTime.Now.ToLongTimeString()} ")
                w.WriteLine($"  :{ex.Message}")
                w.WriteLine("-------------------------------")
                w.WriteLine($"  :{ex.InnerException.Message}")
                w.WriteLine("-------------------------------")
                w.WriteLine($"  :{ex.StackTrace}")
            End Using
            Return False
            Throw
        End Try
    End Function

smtps_pec = 有效的 pec 地址 smtps_pec_porta = 465

我总是收到此错误:

传输无法连接到服务器。调用的目标已引发异常。在 System.Web.Mail.SmtpMail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args) 在 System.Web.Mail.SmtpMail.CdoSysHelper.Send(MailMessage 消息) 在 System.Web.Mail.SmtpMail.Send (MailMessage 消息)

相同的代码在我的开发机器(Windows 10)上工作,但在我的生产机器(Windows Server 2008R2)上不起作用。我尝试禁用 Windows 防火墙,但结果是一样的。

标签: .netvb.net.net-4.0

解决方案


推荐阅读