VB.NET compnent question

Hi,
   I'm trying to build a VB.NET component that will retrieve a list of email addresses from a database("EmailTest") on my local machine  and would send them emails automatically. I'm using a component called Quicksoft.SMTP for the email part. Now when I tested it first by sending email to just one person it worked fine so I know that ther is no problem in the emailing part of it. Its the dataset retrieval that is causing problems and I think its not reading from the database for some reason. I'm new to VB.NET so I can't figure out what is wrong. Could you please look at my code and point to what might be the problem.

Imports Quiksoft.FreeSMTP
Imports System.Data
Imports System.Data.SqlClient

Module Module1

    Sub Main()
        Dim conEmail As SqlConnection
        'Dim strSelect As String
        Dim cmdSelect As SqlCommand
        Dim dtrEmail As SqlDataReader
        Dim CName As String
        Dim CEmail As String



        conEmail = New SqlConnection("Initial Catalog=EmailTest;" & _
               "Data Source=localhost;Integrated Security=SSPI;")


        'Create a Command object.
        cmdSelect = conEmail.CreateCommand
        cmdSelect.CommandText = "SELECT Name, Email FROM Customers"

        'Open the connection.
        conEmail.Open()


        Do While dtrEmail.Read()


            CName = dtrEmail.GetString(0)
            CEmail = dtrEmail.GetString(1)

            Dim msg As New EmailMessage( _
             CEmail, _
             "webadmin@mlmp.org", CName, _
             "Text message.", BodyPartFormat.Plain)
            Dim html As New String( _
             "<html><body><em><b> This is a Test Message for u.</b></em></body></html>")
            msg.BodyParts.Add(html, BodyPartFormat.HTML)
            Dim smtp As New SMTP("mail.mlmp.org")
            smtp.LogFile = "c:\\smtp log.txt"
            smtp.Send(msg)

        Loop
        dtrEmail.Close()
        conEmail.Close()

    End Sub

End Module
BrijBhasinAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
planoczConnect With a Mentor Commented:
Hi BrijBhasin,

Here is where I found a good example for a starting new in VB.Net and an example of senting e-mails

.....http://msdn.microsoft.com/vbasic/downloads/samples/101samples.aspx

0
 
iboutchkineCommented:
'ref to System.Web.dll (.NET) - works only on NT, 2k and XP

Outgoing Mail Server (SMTP) Authentication
In order to send email, you must set your email software to use authentication when connecting to
the outgoing mail server.

--------------------------------------------------------------
EXPLANATION:
Email goes from program to Default SMTP server on IIS where you have to configure Authentication and
Relay. The mail server (like in case of FriendshipDairies.com is 161.58.224.149) must authenticate
the user (oMail.From in this example)
See authentication of Default SMTP server under "SMTP using MS SMTP server"
--------------------------------------------------------------


Imports System.Web.Mail
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
#End Region
    Dim oMail As MailMessage
    Private Sub SendButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendButton.Click
        oMail = New MailMessage()
        oMail = New MailMessage
        With oMail
            'oMail.BodyFormat = MailFormat.Html 'or MailFormat.Text
            .From = "iboutchkine@bla.com"' this name must be authenticated by SMTP server
            .To = "iboutchkine@blabla.com"
            .Subject = "My SMTP Test"
            .Body = "Hi Iouri"
            .Priority = MailPriority.Normal ' Normal, Low or High
        End With

        SmtpMail.SmtpServer = "server.com"

        Try
            SmtpMail.Send(oMail)
        Catch ex As SystemException
            MsgBox(Err.Description & vbCrLf & ex.ToString)
            Exit Sub
        End Try

        MessageBox.Show("Message Sent")

    End Sub
End Class

0
 
Bob LearnedConnect With a Mentor Commented:
There is something cool in ADO.NET when working with datasets, and that is typed datasets.  You can create an SQLDataAdapter, tell it to generate a data set.  You will get an XSD file in your solution that shows the schema structure for all the reference tables.  Then you can use the Intellisense functionality of the IDE, instead of using the SQLDataReader.

Bob
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
BrijBhasinAuthor Commented:
TheLearnedOne,
  I got lost in ur explanation, is there an example of what ur talking abt that I can look at?

Brij
0
 
Bob LearnedCommented:
Look here:

http://community.borland.com/article/0,1410,30294,00.html

It talks about C# with typed datasets, but the concepts are the same.

Bob
0
 
LektranCommented:
Try adding this after you open the connection to the database:

dtrEmail = cmdSelect.ExecuteReader()
0
 
Bob LearnedCommented:
Did any of this make any sense?

Bob
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.