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!