Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
Dim smtpserver As New SmtpClient
smtpserver.Credentials = New Net.NetworkCredential("[email protected]", "xxxxx")
smtpserver.Host = ComboBox1.Text
smtpserver.Port = "587"
Dim des As New TohomeCenter.EmCRMLib.Encryption
Dim mail As New MailMessage
Dim i As Integer
For i = 0 To dt.Rows.Count - 1
mail = New MailMessage
mail.From = New MailAddress("[email protected]")
mail.To.Add(New MailAddress(dt.Rows(i)("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"">")
If Not txtAttachment.Text = Nothing Then
Dim Attach As Net.Mail.Attachment = New Net.Mail.Attachment(txtAttachment.Text)
mail.Attachments.Add(Attach)
End If
mail.IsBodyHtml = True
smtpserver.EnableSsl = True
smtpserver.Send(mail)
'Dim msg As String
'Dim title As String
'Dim style As MsgBoxStyle
'Dim response As MsgBoxResult
'msg = "Your Mail Has Been Sent"
'style = MsgBoxStyle.OkOnly
'title = "Mail Sent Conformation"
'response = MsgBox(msg, style, title)
'If response = MsgBoxResult.Ok Then
' Me.Label1.Text = " "
' Timer1.Stop()
' Timer1.Enabled = False
'End If
'MessageBox.Show("send mail ok")
ProgressBar1.Maximum = 100
MsgBox("ทำการส่ง E-mail เรียบร้อย", MsgBoxStyle.Information, "ขอบคุณ")
Next
Catch ex As Exception
MsgBox("error")
End Try
End Sub
Tag : .NET, Ms SQL Server 2005, Ms SQL Server 2008, VB.NET
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports System.Threading
Namespace AutoSendMail
Public Partial Class Form1
Inherits Form
Private m_index As Integer
Private m_stop As Boolean
Private m_email As List(Of String)
Private m_bg As BackgroundWorker
Public Sub New()
InitializeComponent()
m_email = New List(Of String)()
m_email.Add("[email protected]")
m_email.Add("[email protected]")
m_email.Add("[email protected]")
m_email.Add("[email protected]")
m_email.Add("[email protected]")
m_email.Add("[email protected]")
m_email.Add("[email protected]")
m_email.Add("[email protected]")
m_email.Add("[email protected]")
m_email.Add("[email protected]")
m_bg = New BackgroundWorker()
AddHandler m_bg.DoWork, New DoWorkEventHandler(AddressOf bg_DoWork)
m_index = 0
m_stop = False
progressBar1.Maximum = 10
progressBar1.[Step] = 1
End Sub
Private Sub bg_DoWork(sender As Object, e As DoWorkEventArgs)
While True
If m_stop = True Then
Thread.Sleep(1000)
Continue While
End If
If m_index >= 10 Then
MessageBox.Show("Conpleted")
Exit While
End If
progressBar1.BeginInvoke(New Action(Function()
progressBar1.Value = m_index + 1
End Function))
label1.BeginInvoke(New Action(Function()
label1.Text = "Send mail to " & m_email(m_index)
End Function))
m_index += 1
Thread.Sleep(1000)
End While
End Sub
Private Sub button1_Click(sender As Object, e As EventArgs)
m_stop = False
If m_bg.IsBusy = False Then
m_bg.RunWorkerAsync()
End If
End Sub
Private Sub button2_Click(sender As Object, e As EventArgs)
m_stop = True
End Sub
End Class
End Namespace