Private Sub btnsend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsend.Click
s1 = New System.Threading.Thread(AddressOf Sendmail)
s1.Start()
End Sub
Private Sub Sendmail()
Try
'แก้แล้ววววให้ส่ง 1 ฉบับ ต่อคน เหลือ แต่ ขึ้น progressbar
database.ExecCommand("SELECT_Email1", dr)
While dr.Read
smtpserver.Credentials = New Net.NetworkCredential("[email protected]", "xxxx")
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
Timer1.Enabled = True
ProgressBar1.Maximum = dt.Rows.Count
ProgressBar1.Increment(1)
Application.DoEvents()
lbl1.Text = i.ToString
lbl1.Text = (i / ProgressBar1.Maximum * 100)
lbl1.Text = lbl1.Text + "%"
lblStaus.Text = dt.Rows.Count.ToString
Next
End While
MessageBox.Show("send mail ok")
dr.Close()
Catch ex As Exception
MsgBox("error")
End Try
End Sub
Private Sub testsendmail_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.CheckForIllegalCrossThreadCalls = False
End Sub
ขอบคุนนะคับบบบ
Tag : Ms SQL Server 2005, Ms SQL Server 2008, VB.NET