Need to import Following Name Spaces
Imports System.IO
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Net.Mail
Imports System.Web
Then code as follows,
Dim MailServeName As String = "161.11.11.111"
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ReadData()
End Sub
Private Sub ReadData()
Try
Dim xcel As Excel.Application
Try
xcel = GetObject(, "Excel.Application")
Catch ex As Exception
xcel = New Excel.Application
End Try
xcel.Workbooks.Open("C:\Documents and Settings\epa\Desktop\EmailList.xls")
xcel.Application.Visible = True
xcel.Range("A2").Select()
Dim strName, strEmail, strPosId As String
For i As Integer = 1 To xcel.ActiveSheet.UsedRange.Rows.Count
Try
strName = xcel.ActiveCell(i, 1).VALUE
strEmail = xcel.ActiveCell(i, 2).VALUE
strPosId = ""
sendmail(strName, strEmail, strPosId)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Next
Catch ex As Exception
End Try
End Sub
Private Sub sendmail(ByVal strName As String, ByVal strEmail As String, ByVal strPosId As String)
Try
Dim ma As MailAddress
ma = New MailAddress("User Name", "Display Name")
Dim Message As MailMessage = New MailMessage()
Message.From = ma
Dim strbody As String = String.Empty
strbody = "Hi Jagadeesh"
Message.Body = strbody
Message.To.Add("ToMailId")
Message.Subject = "Subject"
Message.IsBodyHtml = True
Dim MailClient As SmtpClient = New SmtpClient
MailClient.Host = MailServeName
MailClient.Send(Message)
Message.Dispose()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub