Send email error

I'm using this code to send and email from a contact form on my page that you can find on the link below. I'm getting this error message:

CDO.Message.1 error '80040213'
The transport failed to connect to the server.

It points to the .Send line of code. What can be the problem? The configuration data of my email account?

		Const cdoSendUsingMethod        = _
		Const cdoSendUsingPort          = 2
		Const cdoSMTPServer             = _
		Const cdoSMTPServerPort         = _
		Const cdoSMTPConnectionTimeout  = _
		Const cdoSMTPAuthenticate       = _
		Const cdoBasic                  = 1
		Const cdoSendUserName           = _
		Const cdoSendPassword           = _
		Dim objConfig  ' As CDO.Configuration
		Dim objMessage ' As CDO.Message
		Dim Fields     ' As ADODB.Fields
		Dim FirstName, Email, Message
		FirstName = Request.Form("nome")
		Email = Request.Form("email")
		Message = Request.Form("mensagem")
		' Get a handle on the config object and it's fields
		Set objConfig = Server.CreateObject("CDO.Configuration")
		Set Fields = objConfig.Fields
		' Set config fields we care about
		With Fields
			.Item(cdoSendUsingMethod)       = cdoSendUsingPort
			.Item(cdoSMTPServer)            = ""
			.Item(cdoSMTPServerPort)        = 25
			.Item(cdoSMTPConnectionTimeout) = 10
			.Item(cdoSMTPAuthenticate)      = cdoBasic
			.Item(cdoSendUserName)          = "username"
			.Item(cdoSendPassword)          = "password"
		End With
		Set objMessage = Server.CreateObject("CDO.Message")
		Set objMessage.Configuration = objConfig
		With objMessage
			.To       = ""
			.From     = ""
			.Subject  = "Teste enviado em "  & Now() 
			.TextBody = "Mensagem enviada em " & Now() & vbCrLf & "Nome: " & FirstName & vbCrLf & "Email: " & Email & vbCrLf & "Messagem: " & Message
		End With
		Set Fields = Nothing
		Set objMessage = Nothing
		Set objConfig = Nothing

Open in new window

LVL 33
Who is Participating?
Jorge PaulinoIT Pro/DeveloperCommented:
Hi jppinto,
Why don't you use ASP.NET ? Here's an example:

    Public Sub SendMessage(ByVal subject As String, ByVal messageBody As String, ByVal toAddress As String)
            Dim message As New MailMessage()
            With message
                .From = New MailAddress("", "Sender Name")
                .Subject = subject
                .Body = messageBody
            End With
            Dim networkCredentials As New Net.NetworkCredential()
            With networkCredentials
                .UserName = "username"
                .Password = "password"
            End With
            Dim client As New SmtpClient()
            With client
                .Credentials = networkCredentials
                .Host = ""
                .EnableSsl = False
                'Send the e-mail message
            End With
        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
    End Sub

Open in new window

Use jpaulino's suggestion with one minor modificaiton:

.Host = ""

should be

.Host = ""

The point being that the host needs to be the name (or ip address) of the server, not just the domain name.
The problem with the original question may because the username/password is incorrect or your password has expired on the mail server.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.