VB Code to Send Mail and Import Mail Ids
HI I am Attaching a file which is VB Code file.
By this file you will be able to import email addresses from xls file.
If you r file contains many words then this program will import only valid mail ids.
so no need to worry about the import.
now by importing the address you can send mail to these addresses.
Imports System.Text.RegularExpressions
Imports System.IO.File
Imports System.Collections.Generic
Imports System.IO
Imports SendMailToNewUser
Partial Class ImportsContact
Inherits System.Web.UI.Page
Private sr As StreamReader
Private strng As New StringBuilder()
' private void textBox1_PreviewKeyDown ( object sender, PreviewKeyDownEventArgs e )
'{
'if (e.KeyCode == Keys.Return)
'{
'Status.Text = "Loading file...";
'webBrowser1.Navigate ( textBox1.Text );
'richTextBox1.Text = webBrowser1.Document.Body.InnerHtml;
'Status.Text = "File loaded!";
'}
'}
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Panel2.Visible = False
Panel3.Visible = False
End If
End Sub
Protected Sub btnImportfromFile_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnImportfromFile.Click
Panel1.Visible = False
Panel3.Visible = False
Panel2.Visible = True
Dim pattern As String = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"
' Dim pattern As String = "as"
Dim reg As New Regex(pattern)
'Dim lst As String = ReadAllText(FileUpload1.PostedFile.FileName.ToString())
sr = File.OpenText(FileUpload1.PostedFile.FileName.ToString())
strng.Append(sr.ReadToEnd())
'Response.Write(strng.ToString())
Dim mc As MatchCollection = reg.Matches(strng.ToString())
Dim list As New ArrayList()
For Each m As Match In mc
list.Add(m.Value)
txtcontactList.Text += m.Value.ToString() + ";"
'Response.Write("hi" + m.Value.ToString() + "
" + strng.ToString())
Next
End Sub
Protected Sub btnMail_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMail.Click
Panel1.Visible = False
Panel2.Visible = False
Panel3.Visible = True
txtTO.Text = txtcontactList.Text
'txtTO.Enabled = False
txtFrom.Text = "dharmendra.kumkumar@patni.com"
End Sub
Protected Sub btnSendMail_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSendMail.Click
Try
SendMail(txtTO.Text, txtFrom.Text, "zayad.shaikh@patni.com", txtSubject.Text, TextBox4.Text)
Catch ex As Exception
Response.Write("Error Occured" + ex.Message)
End Try
'Response.Write(" ")
' Response.Redirect("Home.aspx?UserID=" + Session.SessionID)
Response.Write("Messase send successfully to " + txtTO.Text + " address")
End Sub
End Class

Please add the code as a resource and not as an attachment