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

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
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<span>
-<span> mail.To.Add("JohnDoe@hills.com") , which is<span>
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<span>
(there are multiply fields containing email address).<span> I<span>
already have a DataSet call -<span> 500_appDataSet1 containing the email address fields.<span>
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.<span>
I would really appreciate to get advice from someone who had this experience. I am not using ASP, just vb.net Form.<span>
Please take in consideration that I am new to VB.Net.<span> Thank you in advance.
Private Sub btnSendEmail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSendEmail.Click
<span> Check to see if subject text box or message text box have values
<span> If Me.txtMessage.Text.Trim = "" Or Me.txtSubject.Text.Trim = ""<span>
Then
<span>
MsgBox("Subject or Message fields are required!", MsgBoxStyle.Exclamation, "Insufficient Data")
<span>
Return
<span> End If
<span> <span> create the mail message
<span> Di mail As New MailMessage()
<span> set the addresses
<span> mail.From = New MailAddress("azula@comm.com")
<span> mail.To.Add("JohnDoe@hills.com")
<span> set subject text box and message text box content
<span> mail.Subject = Me.txtSubject.Text.Trim
<span> mail.Body = Me.txtMessage.Text.Trim
<span> add an attachment from the filesystem
<span> mail.Attachments.Add(New Attachment("C:Customers Statement and InvoicesCustomers pdf Folder33.pdf"))
<span> <span> send the message
<span> Dim smtp As New SmtpClient("local777")
<span> smtp.Send(mail)
<span>
<span> MsgBox("Copies of Statement & Invoices has been sent", MsgBoxStyle.Exclamation, "Send email")
<span> End Sub

View the full article
 
Back
Top