[Solved] How would I be able to send an email through my vb.net application?


10s of googling gives you 10k answers..

The easiest way to send a mail with .net is by using the System.Net.Mail Namespace and a smtp server where you have an e-mail account like mostlikely Gmail.

Imports System.Net.Mail

Module Module1

Sub Main()

    Try

        Dim SmtpServer As New SmtpClient()
        Dim mail As New MailMessage()
        SmtpServer.UseDefaultCredentials = False
        SmtpServer.Credentials = New Net.NetworkCredential("[email protected]", "yourpassword")
        SmtpServer.EnableSsl = True
        SmtpServer.Port = 465
        SmtpServer.Host = "smtp.gmail.com"
        SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network

        mail = New MailMessage
        mail.From = New MailAddress("[email protected]")
        mail.To.Add("[email protected]")
        mail.Subject = "This is the subject"
        mail.Body = "This is the body"

        SmtpServer.Send(mail)

    Catch ex As Exception

        MsgBox(Err.Number & vbNewLine & ex.Message)

    End Try

End Sub

End Module

Hints if this doesn’t work:

  • check your network credentials manually

  • look into your Anti-Virus eventlog, as if you use McAfee, the System.Net.Mail will be blocked as a spam mailworm by your own protection.

  • Use the CDOSYS method to send a mail

  • Use the Microsoft.Office.Interop.Outlook method to send a mail

  • Use Telnet to test your communication with a SMTP server

solved How would I be able to send an email through my vb.net application?