Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
Timer1.Enabled = True
'แก้แล้ววววให้ส่ง 1 ฉบับ ต่อคน เหลือ แต่ ขึ้น progressbar
database.ExecCommand("SELECT_Email1", dr)
While dr.Read
smtpserver.Credentials = New Net.NetworkCredential("[email protected]", "xxxxxxx")
smtpserver.Host = "smtp.live.com"
smtpserver.Port = "587"
mail = New MailMessage
mail.From = New MailAddress("[email protected]")
mail.To.Add(New MailAddress(dr.Item("emailname")))
mail.Subject = txtSuject.Text
mail.Body = txtmess.Text.Replace("<!--Link-->", "<a href=""http://localhost:65150/TEST/frmemailcancel.aspx?email=" & des.EncryptString(Me.txtto.Text) & """ target=""_blank"">")
mail.IsBodyHtml = True
If Not txtAttachment.Text = Nothing Then
Dim attach As New Attachment(txtAttachment.Text)
mail.Attachments.Add(attach)
End If
If Not TextBox1.Text = Nothing Then
Dim attach As New Attachment(TextBox1.Text)
mail.Attachments.Add(attach)
End If
If Not TextBox2.Text = Nothing Then
Dim attach As New Attachment(TextBox2.Text)
mail.Attachments.Add(attach)
End If
smtpserver.EnableSsl = True
smtpserver.Send(mail)
For i As Integer = 1 To dt.Rows.Count Step +1
Timer1.Enabled = True
'Thread.Sleep(50)
ProgressBar1.Value = (AscW(i.ToString.Max))
Application.DoEvents()
lbl1.Text = i.ToString
lbl1.Text = (i / ProgressBar1.Maximum * 100)
lbl1.Text = lbl1.Text + "%"
lblStaus.Text = "จำนวนที่ส่ง:" & i & "ฉบับ"
'ProgressBar1.Maximum = i
ProgressBar1.Increment(AscW(i.ToString.Max))
Next
End While
If dt.Rows.Count = 0 Then
Timer1.Enabled = False
End If
MessageBox.Show("send mail ok")
dr.Close()
Catch ex As Exception
MsgBox("error")
End Try
End Sub
ขอโค้ดตัวอย่างด้วยนะคับบบบบบบ
ขอบคุนนะคับบบ
Tag : MySQL, Ms SQL Server 2005, Ms SQL Server 2008, VB.NET