Solved

VB.NET compnent question

Posted on 2004-04-08
7
256 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

786 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