由于目标机器主动拒绝而无法建立连接

发布于 2024-09-14 10:32:19 字数 2371 浏览 4 评论 0原文

我正在将我的网页从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暮年慕年 2024-09-21 10:32:19

您想要访问的 SMTP 服务器可能位于端口 25 上。

<network host="mail.mydomain.com" port="25"/>

这与 sendusing 指令不同。

The SMTP server you want to reach is probably on port 25.

<network host="mail.mydomain.com" port="25"/>

This is different from the sendusing directive.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文