Aaron Brown
Aaron Brown

Reputation: 291

Error: Failure sending mail.. Unable to read data from the transport connection: net_io_connectionclosed

I've seen other's asking questions about how to fix this error, and the answer is always the same: fix your iis6/7/smtp server. The trouble is, I'm not using my own SMTP server, I'm using Godaddy's!

Godaddy is my domain register. I have purchased email with them, for my domain name. They've provided me with the following information (for connecting to "other" software, other than Outlook, etc):

Account: [email protected] 
Your name: Enter your name
User Name: [email protected] 
Password: Enter your email password
SMTP (Outgoing Mail Server): smtpout.secureserver.net

Yeah, it didn't mention the port. So I looked up more info on smtpout.secureserver.net, and I found also this info (at http://products.secureserver.net/email/email_outlook.htm):

Port: 3535 or 80.

So, here is my code:

Public Function SendMail(ByVal To_Email As String, ByVal Subject As String, ByVal Message As String) As Boolean
    Try
        Dim FROM_EMAIL As String = "MY EMAIL"
        Dim FROM_NAME As String = "MY NAME"
        Dim TheseCredentials As New Net.NetworkCredential(FROM_EMAIL, "MY EMAIL PASSWORD")
        Dim NetMail As New Net.Mail.MailMessage
        Dim MailClient As New Net.Mail.SmtpClient()
        NetMail.From = New Net.Mail.MailAddress(FROM_EMAIL, FROM_NAME)
        NetMail.To.Add(New Net.Mail.MailAddress(To_Email))
        NetMail.IsBodyHtml = True
        NetMail.Subject = Subject
        NetMail.Body = Message
        MailClient.Host = "smtpout.secureserver.net"
        MailClient.Port = 3535
        MailClient.UseDefaultCredentials = False
        MailClient.Credentials = TheseCredentials
        MailClient.Send(NetMail)
        Return True
    Catch ex As Exception
        Return False
    End Try
End Function

I get the error on the MailClient.Send(NetMail) command.

Note: I have NO smtp server running on my computer. But, I don't think I should need it since I'm using a third party smtp server.

Note: my computer is windows web server 2008 R2, I have both iis6 and iis7, and I'm using Visual Studio Express 2013 for Web.

Note: I also tried outgoing ports 80, 587 and 25. Port 25 took about 10 seconds and then gave the error "cannot connect". All the other ports gave the error I'm asking about. I also tried allowing access to all outgoing ports on my firewall.

Upvotes: 0

Views: 5166

Answers (1)

Aaron Brown
Aaron Brown

Reputation: 291

Solved: I had registered my site on godaddy, but I wasn't hosting it with them. Anyway, the problem was my fault. I had not set up the DNS server names for my domain name right. I had to set up my "MX" servers to include:

DNS "MX" server: smtp.secureserver.net (priority 0)
DNS "MX" server: mailstore1.secureserver.net (priority 10)

Once done, I had to wait about an hour (can take 24 hours though) for the DNS to sync. Then bingo, my above code worked just fine. I got those server names by calling godaddy support, and they were the ones who identified (over the phone) that I hadn't set up my MX servers for my site.

Note: I still have NO smtp server running on my computer. And it is NOT necessary to have your own smtp server to send emails with Microsoft Framework IF you have a email provider that allows you to send emails this way (many "free" email providers block it).

Upvotes: 3

Related Questions