Click here to Skip to main content
15,883,928 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to Send Bulk Mails using .Net, Reading Mail Id's From Excel Sheet.
Posted

1 solution

Need to import Following Name Spaces
VB
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900