• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

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?

jppinto

http://www.caraibas.info/luademel/contacto.asp
<%
		Const cdoSendUsingMethod        = _
			"http://schemas.microsoft.com/cdo/configuration/sendusing"
		Const cdoSendUsingPort          = 2
		Const cdoSMTPServer             = _
			"http://schemas.microsoft.com/cdo/configuration/smtpserver"
		Const cdoSMTPServerPort         = _
			"http://schemas.microsoft.com/cdo/configuration/smtpserverport"
		Const cdoSMTPConnectionTimeout  = _
			"http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
		Const cdoSMTPAuthenticate       = _
			"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
		Const cdoBasic                  = 1
		Const cdoSendUserName           = _
			"http://schemas.microsoft.com/cdo/configuration/sendusername"
		Const cdoSendPassword           = _
			"http://schemas.microsoft.com/cdo/configuration/sendpassword"
		
		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)            = "mail.mydomain.pt"
			.Item(cdoSMTPServerPort)        = 25
			.Item(cdoSMTPConnectionTimeout) = 10
			.Item(cdoSMTPAuthenticate)      = cdoBasic
			.Item(cdoSendUserName)          = "username"
			.Item(cdoSendPassword)          = "password"
		
			.Update
		End With
		
		Set objMessage = Server.CreateObject("CDO.Message")
		
		Set objMessage.Configuration = objConfig
		
		With objMessage
			.To       = "myname@mydomain.pt"
			.From     = "rtest@aeiou.pt"
			.Subject  = "Teste enviado em "  & Now() 
			.TextBody = "Mensagem enviada em " & Now() & vbCrLf & "Nome: " & FirstName & vbCrLf & "Email: " & Email & vbCrLf & "Messagem: " & Message
			.Send
		End With
		
		Set Fields = Nothing
		Set objMessage = Nothing
		Set objConfig = Nothing
		%>

Open in new window

0
jppinto
Asked:
jppinto
1 Solution
 
jpaulinoCommented:
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)
 
        Try
            Dim message As New MailMessage()
            With message
                .From = New MailAddress("mail@domain.com", "Sender Name")
                .To.Add(toAddress)
                .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 = "domain.com"
                .EnableSsl = False
 
                'Send the e-mail message
                .Send(message)
            End With
 
        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
    End Sub

Open in new window

0
 
jmwheelerCommented:
Use jpaulino's suggestion with one minor modificaiton:

.Host = "domain.com"

should be

.Host = "mail.mydomain.pt"

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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now