Wednesday, March 2, 2016

SEND EMAIL SIMPLE VB.NET

//function

Public Shared Sub SendMail(ByVal from As String, ByVal [to] As String, ByVal subject As String, ByVal body As String, ByVal smtpServer As String, ByVal smtpUsername As String, _
    ByVal smtpPassword As String)
        Dim message As New MailMessage(from, [to], subject, body)
        Dim smtpClient As New SmtpClient(smtpServer)
        smtpClient.UseDefaultCredentials = False
        Dim credentials As New NetworkCredential(smtpUsername, smtpPassword)
        smtpClient.Credentials = credentials
        smtpClient.Send(message)
    End Sub

//call on button click

 Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        SendMail("kapil@suprol.com", "kapil@suprol.com", "hello", "body", "192.168.1.123", "kapil@suprol.com", "suprol")
       
    End Sub

No comments: