We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

VB.NET compnent question

BrijBhasin
BrijBhasin asked
on
Medium Priority
291 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
Comment
Watch Question

CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
'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

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

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

Brij
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
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

Commented:
Try adding this after you open the connection to the database:

dtrEmail = cmdSelect.ExecuteReader()
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
Did any of this make any sense?

Bob
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.