message.To.Add(mailTo);
当我尝试从数据库中获取电子邮件数据以发送电子邮件时,此行出现错误。
void Sendmail_Click(object sender, EventArgs e)
{
List<DAL.Customer> mailId = (from rs in General.db.Customers
where rs.IsActive == true
select rs).ToList();
StringBuilder mailstring = new StringBuilder();
foreach (var item in mailId)
{
mailstring.Append(item.Email).Append(",");
}
string mailTo = mailstring.ToString();
if (mailTo.EndsWith(","))
{
mailTo = mailTo.Remove(mailTo.LastIndexOf(","));
}
SmtpClient smtp = new SmtpClient();
mailMessage.From = fromMail;
mailMessage.To.Add(new MailAddress(mailTo));
mailMessage.IsBodyHtml = true;
lblStatus.Text = "Email sent successfully";
}