title: How to test SMTP connection before SMTPClient.Send [VB.NET]
body: <p>Pretty new to programming here.</p>
  
  <p>The program I'm currently working on needs to send an email with logs. 
  Working great if I'm using the right server host but when I'm trying with a "false" server host my program sure can't connect, but it immediatly crash, I can't raise any exception, can't tell the user he's doing something wrong, nothing.</p>
  
  <p>So I guess I have to test the connection before SMTPClient.Send but I can't seem to find how...</p>
  
  <p>How can I test a SMTP Server connection in VB.NET ?</p>
  
  <p>That's what I'm using :</p>
  
  <pre><code>    Try
          Dim SmtpServer As New SmtpClient()
          With SmtpServer
              .EnableSsl = False
              .UseDefaultCredentials = False
              .Credentials = New Net.NetworkCredential(MailUser, MailPassword)
              .Port = 25
              .Host = ServerAdress
          End With
  
          Dim mail As New MailMessage()
          With mail
              .From = New MailAddress(MailSender)
              .To.Add(MailReceiver)
              .CC.Add(MailCC)
              .Subject = MailObject
              .Body = MailBody
          End With
  
          SmtpServer.Send(mail)
  
      Catch ex As Exception
          MsgBox(ex.ToString)
      End Try
  </code></pre>