CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2009
    Posts
    177

    SMTP Send Email Failed

    I have the following code to send email through SMTP:


    Code:
     Private Sub SendMailToAdmin()
            Try
                RecipientAddress = ""
                Dim YesDate As String = Now.AddMonths(0).ToString("MMM yyyy")
                Dim oMsg As New MailMessage()
                oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1)
                oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", SenderAddress)
                oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", SenderPassword)
    
                oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", MailServer)
                oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout", 10)
                ' oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", 2)
                oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 587)
                oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", True)
    
    
                oMsg.From = DisplayID
                oMsg.To = strEmailErrorTo
                oMsg.Cc = strEmailErrorCc
                oMsg.Subject = "Testing Email "
    
                oMsg.BodyFormat = MailFormat.Html
    
                oMsg.Body = "<HTML><HEAD><style>.Bd1 { FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Verdana; TEXT-ALIGN: LEFT } "
                oMsg.Body &= "</style></HEAD><BODY class=Bd1>"
                oMsg.Body &= "Testing Email<br /><br />"
                oMsg.Body &= "</BODY></HTML>"
    
                SmtpMail.SmtpServer = MailServer
                SmtpMail.Send(oMsg)
    
                oMsg = Nothing
            Catch ex As Exception
                ErrorToAdmin("Billing: Failed To Send Out Testing Email " + ex.Message)
            End Try
    
        End Sub

    I get the error when trying to send out email:

    The transport failed to connect to the server.


    Does anyone know the cause of it??

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: SMTP Send Email Failed

    Code:
                SmtpMail.SmtpServer = MailServer
    What mail server are you trying to send to
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured