я пытаюсь достичь в своем коде ниже, чтобы отправить электронное письмо для каждого адреса электронной почты, который можно найти в моей базе данных. Моя проблема заключается в том, что когда я нажимаю кнопку отправки, появляется сообщение об ошибке «The specified string is not in the form required for an e-mail address.
» в строке mail.Bcc.Add(MyVar.Text)
.
private void sendmail()
{
Label MyVar = new Label();
foreach (DataRowView UserEmail in SelectUserProfile.Select(DataSourceSelectArguments.Empty))
{
MyVar.Text = "";
MyVar.Text += UserEmail["EMAIL"].ToString() + "; ";
}
//This line takes the last ; off of the end of the string of email addresses
MyVar.Text += MyVar.Text.Substring(0, (MyVar.Text.Length - 2));
MailMessage mail = new MailMessage();
mail.Bcc.Add(MyVar.Text);
mail.From = new MailAddress("syntaxbugerror@gmail.com");
mail.Subject = "New Member Application";
mail.Body = "Good day, in this e-mail you can find a word document attached in which it contains new membership application details.";
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Credentials = new System.Net.NetworkCredential("myusername@gmail.com", "mypassword");
smtp.EnableSsl = true;
smtp.Send(mail);
}
Эрни