The following code is giving me warnings and errors in Visual Studio, though the code works fine.
The code: Imports System.Threading.Tasks gives a warning that it doesn't contain any public member or cannot be found.
The code: Parallel.ForEach... gives an Error that it is not declared.
The code: Function(row) gives and Error that Visual Basic 9.0 does not support this kind of lambda expression.
I'm using Visual Studio 2013, any thoughts as to where to look for the solutions to these warnings and errors?
I am uncertain as to the exact reasons or where to look for needed corrections.
Imports System.Net
Imports System.Net.Mail
Imports System.Data
Imports System.Threading.Tasks
Imports System.Data.SqlClient
Partial Class VB
Inherits System.Web.UI.Page
Protected Sub SendBulkEmail(sender As Object, e As EventArgs)
Dim constr As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Dim con As SqlConnection = New SqlConnection(constr)
Dim cmd As SqlCommand = New SqlCommand("SELECT Name, EmailAddress FROM Email", con)
Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim dtCustomers As DataTable = New DataTable()
da.Fill(dtCustomers)
Dim subject As String = "Welcome Email"
Dim body As String = "To opt-out "
body += "<a href = '" & Request.Url.AbsoluteUri.Replace("VB.aspx", "optout.asp?Email=" & dtCustomers.Rows(0)("DEREmailAddress").ToString()) & "'>click here</a>."
Parallel.ForEach(dtCustomers.AsEnumerable(), _
Function(row)
Return SendEmail(row("EmailAddress").ToString(), subject, String.Format(body, row("Name")))
End Function)
End Sub
Private Function SendEmail(recipient As String, subject As String, body As String) As Boolean
Dim mm As New MailMessage("someone@somewhere.com", recipient)
mm.Subject = subject
mm.Body = body
mm.IsBodyHtml = True
Dim smtp As New SmtpClient()
smtp.Host = "somewhere"
smtp.EnableSsl = False
Dim NetworkCred As New NetworkCredential()
NetworkCred.UserName = ""
NetworkCred.Password = ""
smtp.UseDefaultCredentials = True
smtp.Credentials = NetworkCred
smtp.Port = 25
smtp.Send(mm)
Return True
End Function
End Class