Solved

VB.NET compnent question

Posted on 2004-04-08
7
254 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:BrijBhasin
7 Comments
 
LVL 27

Accepted Solution

by:
planocz earned 150 total points
ID: 10785421
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
 
LVL 28

Expert Comment

by:iboutchkine
ID: 10785472
'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
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 100 total points
ID: 10785707
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:BrijBhasin
ID: 10785722
TheLearnedOne,
  I got lost in ur explanation, is there an example of what ur talking abt that I can look at?

Brij
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10785771
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
 
LVL 3

Expert Comment

by:Lektran
ID: 10795372
Try adding this after you open the connection to the database:

dtrEmail = cmdSelect.ExecuteReader()
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10825476
Did any of this make any sense?

Bob
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now