Hi...
I want to send an email to multiple recipients from my database in sql server. I'm using .vb to do it.. Any suggestions on how i can use a for loop to send my email? Thanks.
I want to send an email to multiple recipients from my database in sql server. I'm using .vb to do it.. Any suggestions on how i can use a for loop to send my email? Thanks.
Code:
Dim cmdEmails As New SqlCommand("select student_email from student", conn) conn.Open() Dim ds As New DataTable ds = New DataTable Dim mailMessage As New MailMessage() mailMessage.From = New MailAddress("0609887e@student.tp.edu.sg") mailMessage.To.Add(dd_email.SelectedValue) mailMessage.Subject = txt_subj.Text mailMessage.Body = txt_content.Text 'Dim msg As New MailMessage(dd_email.SelectedValue, txt_subj.Text, txt_content.Text) Try If fileUpload.PostedFile.FileName = "" Then Else mailMessage.Attachments.Add(New System.Net.Mail.Attachment(fileUpload.PostedFile.FileName)) End If Dim smtpMail As New SmtpClient("localhost") smtpMail.Send(mailMessage) lbl_status.Visible = True lbl_status.Text = "Message sent." Catch ex As Exception lbl_status.Visible = True lbl_status.Text = "Error" conn.Close() End Try End Sub End Class
Comment