Imports System.Net.MailImports System.NetImports MainImports System.Data.SqlClientPartial Class Teacher_Email_Class Inherits System.Web.UI.Page Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click Dim sql As String TextBox1.Text = sql = Select email FROM Registration WHERE ' You query Dim Conn As String = ConfigurationManager.ConnectionStrings(ConnectionString).ConnectionString Dim SQLConn As New SqlConnection(Conn) Dim cmd As New SqlCommand(sql, SQLConn) Dim reader As SqlDataReader SQLConn.Open() reader = cmd.ExecuteReader() While reader.Read() If reader.HasRows Then TextBox1.Text &= reader(email) & ; End If End While reader.Close() SQLConn.Close() End Sub Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click Dim arr() As String arr = TextBox1.Text.Split(;) Dim mailmessage As New Mail.MailMessage() mailmessage.From = New MailAddress(myemil@gmail.com, Title) mailmessage.ReplyTo = New MailAddress(TextBox4.Text, Session(FName)) 'To For Each s As String In arr mailmessage.To.Add(New MailAddress(s)) Next 'mailmessage.Subject = DropDownList1.SelectedValue mailmessage.Subject = TextBox3.Text TextBox2.Text = SingleQuoteToDoubleQuote(TextBox2.Text) mailmessage.Body = TextBox2.Text If FileUpload1.HasFile Then mailmessage.Attachments.Add(New Attachment(FileUpload1.PostedFile.FileName)) End If Dim smtp As SmtpClient = New SmtpClient() Try 'Your SMTP Server smtp.Host = smtp.gmail.com 'SSL Settings depending on your Server smtp.EnableSsl = True 'Creadentials for the Serve Dim NetworkCred As Net.NetworkCredential = New System.Net.NetworkCredential() 'Your Email NetworkCred.UserName = yourusername 'Your Password NetworkCred.Password = yourpassword smtp.UseDefaultCredentials = True smtp.Credentials = NetworkCred 'Port No of the Server smtp.Port = 587 smtp.Send(mailmessage) Catch ex As Exception Label1.Text = ex.Message Finally smtp = Nothing mailmessage = Nothing End Try End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim Conn As String = ConfigurationManager.ConnectionStrings(ConnectionString).ConnectionString Dim SQLConn As New SqlConnection(Conn) Dim sql As String = SELECT email FROM Registration WHERE UID=' _ & Session(UserName) & ' ORDER BY UID ASC Dim cmd As New SqlCommand(sql, SQLConn) Dim reader As SqlDataReader SQLConn.Open() reader = cmd.ExecuteReader() reader.Read() TextBox4.Text = reader(email) reader.Close() SQLConn.Close() End SubEnd Class