I am creating a newsletter application for a client in asp.net / vb.net. When I try to send the mail I get the following error…
The transport failed to connect to the server.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: The transport failed to connect to the server.
Source Error:
Line 32: objEmail.BodyFormat = MailFormat.Text
Line 33: SmtpMail.SmtpServer = “mail.domain.com”
Line 34: SmtpMail.Send(objEmail)
Line 35: lblEmails.Text += sEmail & “ ”
Line 36: End While
Is there a problem with my code or is this a problem on the mail server? Thank you.
As you are using mail.domain.com as smtp in your code. You need to use smtp authentication. Please use real email address as user name and its password as password for smtp authentication.
Might you have some sample code to help integrate the authentication into my application? My current code is as follows. I’ve tried using some different methods to do the authentication but none have worked.
Dim sEmail As String
Dim sBody As String
Sub Send2Mail(ByVal sender As Object, ByVal e As System.EventArgs)
Dim objEmail As MailMessage = New MailMessage
sBody = "This is our test email to you"
objEmail.Subject = "This is my Subject"
Dim MySQL As String = "Select fname, email from Customers"
Dim MyConn As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("bowlher_sunmansConnectionString").ConnectionString)
Dim objDR As SqlDataReader
Dim Cmd As New SqlCommand(MySQL, MyConn)
MyConn.Open()
objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
While objDR.Read()
sEmail = objDR("email")
objEmail.To = sEmail
objEmail.From = "[email protected]"
objEmail.Body = sBody & vbCrLf & "Name: " & objDR("fname") & vbCrLf & "Email: " & sEmail
objEmail.BodyFormat = MailFormat.Text
SmtpMail.SmtpServer = "mail.adrenterprises.com"
SmtpMail.Send(objEmail)
lblEmails.Text += sEmail & "<br>"
End While
MyConn.Close()
End Sub
This is the code I’ve used to authenticate but still gives the same error.