Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a database with a table called "members" with five fields in it called MemberID, Husband, Wife, HEmail and WEmail.

 

I am wanting to be able to send an email from a web form to all the people in table using VB.NET including HEmail and WEmail. The web form will include a Subject and Information field.

 

I am trying to do this without using a third party application like AspEmail so I am not bound

to any particular web host.

 

Can someone help me with this?

 

Thanks,

Tim

  • *Experts*
Posted

Look into this class:

System.Web.Mail.SmtpMail

Its small and pretty selfexplanatory :) But you will need an SMTP service running on your server.

Posted

Well, not being too good at coding VB.NET I really am looking for some example code that will extract the emails from the datbase and then send the form field values to the list of emails.

 

Thanks for the help

  • *Experts*
Posted

First you have to connect to the database...

Dim Conn as new SqlConnection("you connection string goes here")'or OleDBConnection if you use Access or something else
Dim Cmd as New SqlCommand("SELECT email FROM users", Conn)
'lets assume your email field is called email and your table is called users
Dim reader as SqlDataReader
Conn.Open() 'open the connection
Dim emails as new ArrayList() 'to strore emails
reader = Cmd.ExecuteReader() 'let the data reader get the emails
Do While reader.Read() 'Keep reading until you run out of records
       emails.add(reader.GetString(numberofyouremailcolumn))
Loop
reader.Close()
Conn.Close()

 

To send a message:

Dim msg as new Web.Mail.MailMessage()
msg.To = "someones email"
'and another settings for the msg object...
Dim smtpserver as Web.Mail.SMTPMail
smtpserver.Send(msg)

 

I hope this clears some things :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...