由于目标机器主动拒绝而无法建立连接
我正在将我的网页从 asp classic 升级到 asp.net。我之前的代码使用 CDO 发送电子邮件。
sch = "http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(sch & "sendusing") = 2
.Item(sch & "smtpserver") = "mail.mydomain.com"
.update
End With
Set cdoMessage = CreateObject("CDO.Message")
strTo = "[email protected]"
strFrom = "[email protected]"
strSubject = "email subject"
strBody = strBody & "This is the email body"
With cdoMessage
Set .Configuration = cdoConfig
.From = strFrom
.To = strTo
.Subject = strSubject
.HTMLBody = strBody
.Send
End With
Set cdoConfig = Nothing
Set cdoMessage = Nothing
这段代码工作正常,但我想从我的 asp.net 页面发送电子邮件。当我从 .net 页面发送时,我收到错误消息:“无法建立连接,因为目标计算机主动拒绝它 xx.xx.xxx.xxx:2”
我的 web.config 设置:
<system.net>
<mailSettings>
<smtp from="[email protected]">
<network host="mail.mydomain.com" port="2"/>
</smtp>
</mailSettings>
</system.net>
以及代码部分给我错误:
Dim mailmsg As New MailMessage("[email protected]", txtSubmitterEmail.Text)
mailmsg.Subject = "subject here"
mailmsg.Body = "mail body here"
mailmsg.IsBodyHtml = True
Dim smtp As New SmtpClient
smtp.Send(mailmsg)
我对 .Net 相当陌生,但我已经搜索了几个小时,但无法找出旧代码有效但新代码无效的原因。预先感谢您的帮助!
I'm in the process of upgrading my web pages from asp classic to asp.net. My previous code used CDO to send emails.
sch = "http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(sch & "sendusing") = 2
.Item(sch & "smtpserver") = "mail.mydomain.com"
.update
End With
Set cdoMessage = CreateObject("CDO.Message")
strTo = "[email protected]"
strFrom = "[email protected]"
strSubject = "email subject"
strBody = strBody & "This is the email body"
With cdoMessage
Set .Configuration = cdoConfig
.From = strFrom
.To = strTo
.Subject = strSubject
.HTMLBody = strBody
.Send
End With
Set cdoConfig = Nothing
Set cdoMessage = Nothing
This code works fine but I'd like to send emails from my asp.net pages. When I send from the .net pages, I get the error message: "No connection could be made because the target machine actively refused it xx.xx.xxx.xxx:2 "
My web.config settings:
<system.net>
<mailSettings>
<smtp from="[email protected]">
<network host="mail.mydomain.com" port="2"/>
</smtp>
</mailSettings>
</system.net>
And the section of code that is giving me the error:
Dim mailmsg As New MailMessage("[email protected]", txtSubmitterEmail.Text)
mailmsg.Subject = "subject here"
mailmsg.Body = "mail body here"
mailmsg.IsBodyHtml = True
Dim smtp As New SmtpClient
smtp.Send(mailmsg)
I'm rather new to .Net but I've searched for hours and can not come up with a reason why the old code works but the new doesn't. Thanks in advance for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想要访问的 SMTP 服务器可能位于端口 25 上。
这与
sendusing
指令不同。The SMTP server you want to reach is probably on port 25.
This is different from the
sendusing
directive.