开发者

No connection could be made because the target machine actively refused it

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 = "toaddr@mydomain.com"

                strFrom = "fromaddr@mydomain.com"

                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="myemail@mydomain.com">
            <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("myemail@mydomain.com", 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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜