Reputation: 2607
Apologies as I'm a bit of a beginner with this. I'm trying to send an email from my ASP.NET website using the following code (obviously replacing the hostname, username and password with the actual values):
Public Shared Sub Send(ByVal ToEmail As String, ByVal FromEmail As String, ByVal Subject As String, ByVal Message As String)
Dim mm As New MailMessage(FromEmail, ToEmail, Subject, Message)
Dim smtp As New SmtpClient("hostname")
smtp.Credentials = New NetworkCredential("username", "password")
smtp.Send(mm)
End Sub
When trying to send out the mail I'm receiving this error:
"Unable to read data from the transport connection: net_io_connectionclosed."
I've had a look on various forums to try to find some help with this but I'm not really sure what I should be doing to recify this.
Any help would be very much appreciated. Thanks.
Upvotes: 0
Views: 2401
Reputation: 2607
Thanks to everyone for their responses. I actually managed to resolve this in the end by contacting Namesco - they said all I need to do is change the hostname that I had put in to "localhost" and it's worked.
Upvotes: 1
Reputation: 647
ADD the below lines to your web.config file
<system.net>
<mailSettings>
<smtp from="[email protected]">
<network host="smtp.yourdomain.com" port="25" userName="[email protected]" password="XXXXX" />
</smtp>
</mailSettings>
</system.net>
Below is the code to send mail hope this helps
Dim mMailMessage As New MailMessage()
mMailMessage.From = New MailAddress("[email protected]")
If Not String.IsNullOrEmpty("[email protected]") Then
mMailMessage.ReplyTo = New MailAddress("[email protected]")
End If
mMailMessage.To.Add(New MailAddress("[email protected]"))
mMailMessage.Bcc.Add(New MailAddress("[email protected]"))
mMailMessage.CC.Add(New MailAddress("[email protected]"))
mMailMessage.Subject = "some subject"
mMailMessage.Body = "some body"
mMailMessage.IsBodyHtml = False
mMailMessage.Priority = MailPriority.Normal
Try
Dim mSmtpClient As New SmtpClient()
mSmtpClient.Send(mMailMessage)
Catch ex As SmtpException
Debug.Print("Unable to send message " & ex.Message)
End Try
Upvotes: 0
Reputation: 4074
Basically your SMTP server is blocking your request to send mail.
You can easily test this yourself by opening a command window and use the telnet command to try and connect to the mail server - it will kick you out immediately.
I haven't used Namesco before, but this problem was resolved by adding the IP address of the server trying to send the mail to the list of allowed machines in IIS.
I'm guessing Namesco won't change the setting to "All Unassigned" as that would grant anyone permission to send mail.
Upvotes: 0
Reputation: 11858
You haven't set your SMTP server in your web.config.
See the web.config in the article Sending Email with System.Net.Mail
You can do this in IIS, but I would recommend setting it in the application's web.config for easier access by the development team.
Upvotes: 0