CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2012
    Posts
    2

    Get & send email with attachment from sql view address field within VB.Net 2010

    Hello,
    I have a simple email program from vb.net 2010 the program works successfully. Within the code I want to change part of a code - mail.To.Add("JohnDoe@hills.com") , which is hard coded and get vb to get the various email address from a sql server view (2005) called vlv_customers the view contains, a field call EmailAddrAddress, EmailAddress2, EmailAddress3 (there are multiply fields containing email address). I already have a DataSet call - 500_appDataSet1 containing the email address fields. How can I get vb.net to read from the view the various email address fields (some fields maybe Null - not having any address at all ) and send out the email with the attachment to single or multiple email address. I would really appreciate to get advice from someone who had this experience. I am not using ASP, just vb.net Form. Please take in consideration that I am new to VB.Net. Thank you in advance.

    Private Sub btnSendEmail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSendEmail.Click
    'Check to see if subject text box or message text box have values
    If Me.txtMessage.Text.Trim = "" Or Me.txtSubject.Text.Trim = "" Then
    MsgBox("Subject or Message fields are required!", MsgBoxStyle.Exclamation, "Insufficient Data")
    Return
    End If
    'create the mail message
    Di mail As New MailMessage()
    'set the addresses
    mail.From = New MailAddress("azula@comm.com")
    mail.To.Add("JohnDoe@hills.com")
    'set subject text box and message text box content
    mail.Subject = Me.txtSubject.Text.Trim
    mail.Body = Me.txtMessage.Text.Trim
    'add an attachment from the filesystem
    mail.Attachments.Add(New Attachment("C:\Customers Statement and Invoices\Customers pdf Folder\33.pdf"))
    'send the message
    Dim smtp As New SmtpClient("local777")
    smtp.Send(mail)

    MsgBox("Copies of Statement & Invoices has been sent", MsgBoxStyle.Exclamation, "Send email")

    End Sub

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Get & send email with attachment from sql view address field within VB.Net 2010

    It is quite difficult reading your post. Please use CODE tags :

    http://forums.codeguru.com/showthrea...for-more-info)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured