Raja A

Raja A

  • NA
  • 26
  • 68.7k

I cannot send mail to more than 10 recipients

Jan 4 2014 6:23 AM
Hi,
     I cannot send mail to more than 10 recipients.. using the following code.. Anyone help me for this.. 
 
eMails = db.EMailLists.OrderBy(x => x.ID).Select(x => x.EMail).Cast<string>().ToArray();
ApplicationContext.SendMail(fromUser.EMail, txtName.Text,
 eMails, null, null,
txtSubject.Text,
CKEditor1.Text,
ApplicationContext.SMTP_HOST,
 ApplicationContext.SMTP_PORT,
 null, System.Text.Encoding.Default);
 
public static string SendMail(string fromAddress, string fromDisplayName, string[] toAddresses, string[] ccAddresses, string[] bccAddresses, string subject, string body, string SmtpHost, int port, string[] attachments, Encoding contentEncoding)
{
string result = "";
try
{
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateCertificate);
int i = 0;
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress(fromAddress, fromDisplayName);
for (i = 0; i < toAddresses.Length; i++)
{
mailMessage.To.Add(toAddresses[i]);
}
mailMessage.Subject = subject;
mailMessage.Body = body;
mailMessage.Priority = MailPriority.High;
mailMessage.BodyEncoding = contentEncoding;
mailMessage.IsBodyHtml = true;
if (ccAddresses != null)
{
for (i = 0; i < ccAddresses.Length; i++)
{
mailMessage.CC.Add(ccAddresses[i]);
}
}
if (bccAddresses != null)
{
for (i = 0; i < bccAddresses.Length; i++)
{
mailMessage.Bcc.Add(bccAddresses[i]);
}
}
SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
// SmtpClient smtpClient = null;
//if (!string.IsNullOrEmpty(SmtpHost) && port != 0)
//smtpClient = new SmtpClient(SmtpHost, port);
// else
// smtpClient = new SmtpClient();
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.Credentials = new System.Net.NetworkCredential("[email protected]", "sha2sha2sha");
smtpClient.EnableSsl = true;
if (attachments != null)
{
for (i = 0; i < attachments.Length; i++)
{
mailMessage.Attachments.Add(new Attachment(attachments[i]));
}
}
smtpClient.Send(mailMessage);
result = "Success";
}
catch (Exception ex)
{
result = "Failure due to " + ex.Message;
}
return result;
}