My current problem is that I have set up a list view on aspx page which displays the emails on a selecting sql statement. I want to be able to take the email value (multiple listed) and insert them into .cs email function (specifically the toEmail string. The two problems I have would be im not sure how to take a value out of list view, and im not sure how to implement a for loop to insert more than one value to be assigned to toEmail.
Appreciate the help, many thanks
.cs code
MailMessage message = new System.Net.Mail.MailMessage();
string fromEmail = lectureremail.Text;
string fromPW = userpassword;
// want toEmail value be selected from listview (which will contain multiple values)
string toEmail =;
message.From = new MailAddress(fromEmail);
message.To.Add(toEmail);
message.Subject = txtSubject.Text;
message.Body = txtBody.Text;
message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
using (SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587))
{
smtpClient.EnableSsl = true;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential(fromEmail, fromPW);
smtpClient.Send(message.From.ToString(), message.To.ToString(),
message.Subject, message.Body);
}
List view information on .aspx:
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource2" GroupItemCount="3"
asp:Label ID="emailLabel" runat="server" Text='<%# Eval("email") %>' />
<br />
</td>
</AlternatingItemTemplate>
/asp:ListView>