Question How to Select All email from users database and then send ALL an email msg to them?

jhekz41

New member
Joined
Sep 30, 2012
Messages
3
Programming Experience
Beginner
Im new here in this forum and in visual basic programming. im using microsoft visual studio- VB.net

here's my code:

Try
cnn.Open()
' query the email address of the students in tbl_students'
Dim sQuery As String = "Select std_eadd from tbl_students"

Dim cmdCommand As New MySqlClient.MySqlCommand(sQuery, cnn)
cmdCommand.ExecuteNonQuery()

Dim dbaseStd As New DataTable("Result")
Dim sqlAdapter As New MySqlClient.MySqlDataAdapter()
sqlAdapter.SelectCommand = cmdCommand
sqlAdapter.Fill(dbaseStd)

dim recipient as string
recipient = ?? The selected std_eadd query?

'code for sending mail'
SmtpServer.Credentials = New Net.NetworkCredential("jhekuzai@gmail.com", "********")
SmtpServer.Port = 587
SmtpServer.Host = "smtp.gmail.com"
SmtpServer.EnableSsl = True
SmtpServer.EnableSsl = True
mail.To.Add(recipient)
mail.From = New MailAddress("DSSniRobManosca@yahoo.com")
mail.Subject = (txtSubject.Text)
mail.Body = (rtxtMsg.Text)
SmtpServer.Send(mail)


Catch ex As MySqlClient.MySqlException
MsgBox(ex.Message.ToString)
Finally
cnn.Close()
txtSubject.Clear()
rtxtMsg.Clear()


End Try



*Pls Help me :| for my final defense in school...
 
If this is for your final project then presumably you have learned about loops by now, which are what you use when you want to repeat basically the same action multiple times. When you want to repeat basically the same action for each item in a list you use... you guessed it: a For Each loop. The list is the Rows of the DataTable and the action is adding the email address to the To collection of the MailMessage.
 
Back
Top