How to send an email by authenticating with any mail server

If you want to send an email from an application that might not be on a server that allows relaying you can use the System.Net.NetworkCredential. Just add your account login and password and your email will route through the remote server.

    Dim sTo As String = “someone@someemail.com
    Dim sFrom As String = “me@myemail.com
    Dim sSubject As String = “Using the new SMTP client.”
    Dim sBody As String = “Using this new feature, you can send an e-mail message from an application very easily.”
    Dim msg As New Net.Mail.MailMessage(sFrom, sTo, sSubject, sBody)
 
    Dim client As New Net.Mail.SmtpClient(“mail.myemail.com”, 25)
    Dim SMTPUserInfo As New System.Net.NetworkCredential(“me@myemail.com“, “password”)
    client.UseDefaultCredentials = False
    client.Credentials = SMTPUserInfo
 
    client.Send(msg)