I am trying to develop an application which sends email to multiple recepients.
I am reading all the mail addresses from a text file line by line.But I am wondering ..for example I have 50 mail addresses in my list and something went wrong with the number 45.
How can I inform the user about about it and is it possibble sending the rest of the list?
private void Senmail(IEnumerable<string> list)
{
var mes = new MailMessage {From = new MailAddress(_uname.Trim())};
var col = new MailAddressCollection();
foreach (string adres in list)
{
col.Add(adres);
}
for (int i = 0; i < GetList().Count(); i++)
{
mes.To.Add(col[i].Address);
}
mes.Subject = txtbody.Text;
mes.Body = txtmail.Text;
mes.Attachments.Add(new Attachment(_filename));
var client = new SmtpClient
{
Port = 587,
Host = "smtp.gmail.com",
EnableSsl = true,
Timeout = 5000,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(_uname, _pass),
};
object userState = mes;
client.SendAsync(mes,userState);
client.SendCompleted += client_SendCompleted;
MessageBox.Show("ok");
}
void client_SendCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
if (e.Error!=null)
{
//
}
}