.net - 在 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 防火墙,但结果是一样的。
解决方案
推荐阅读
- c# - 当应用程序在后台 Xamarin.Android 中时,无法第二次获得意图额外的文本
- sql - 在 postgresql 中有一组指令的函数中,查询没有结果数据的目的地
- ios - 如何定义具有动态缓冲区声明的金属着色器?
- php - 当我在 foreach 循环中(使用 post 方法)时无法访问输入的值
- android - ArrayList 在初始化后立即为空
- python - groupby + apply 导致一系列同时出现在索引和列中 - 如何防止它?
- ansible - Ansible playbook 可在缺少时在 IOS 设备上添加本地帐户
- ios - CIImage在SWIFT中的矩形到正方形
- python - Tkinter OOP 在实例方法中更新小部件
- ruby-on-rails - 查找与控制器中其他记录相关的记录(ruby on rails)