The below code works when there are a few element in the "To" list but if i add a large amount, noone recieves the mail . Any clues why this code below would work with a few elments but not with more than one. Also, is there anyway to debug this in terms of actually seeing what is getting sent out from the mail server?
public static void SendMail(string fromEmailAddress_, string[] toEmailAddress_, string[] ccAddress_, string[] bccAddress_, string subject_, string body_, Attachment[] attachments_)
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress(fromEmailAddress_);
foreach (string email in toEmailAddress_)
{
if (IsValidEmail(email))
{
msg.To.Add(new MailAddress(email.Trim()));
}
}
if (ccAddress_ != null)
{
foreach (string email in ccAddress_)
{
if (IsValidEmail(email))
{
msg.CC.Add(new MailAddress(email.Trim()));
}
}
}
if (bccAddress_ != null)
{
foreach (string email in bccAddress_)
{
if (IsValidEmail(email))
{
msg.Bcc.Add(new MailAddress(email.Trim()));
}
}
}
if (attachments_ != null)
{
foreach(Attachment attachment in attachments_)
{
msg.Attachments.Add(attachment);
}
}
msg.Subject = subject_;
msg.Body = body_;
msg.IsBodyHtml = true;
msg.Priority = MailPriority.High;
NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential("[email protected]", "password");
SmtpClient c = new SmtpClient("mail.salemgolfclub.org");
c.UseDefaultCredentials = false;
c.Credentials = basicAuthenticationInfo;
try
{
c.Send(msg);
}
catch (Exception)
{
}
}