Send email error

Posted on 2009-02-12
Last Modified: 2013-11-19
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

Question by:jppinto
    LVL 48

    Accepted Solution

    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

    LVL 11

    Expert Comment

    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.
    LVL 16

    Expert Comment

    The problem with the original question may because the username/password is incorrect or your password has expired on the mail server.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
    SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
    Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
    The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now