Click here to Skip to main content
15,906,558 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have developed a program that sends 70-80 emails but when i enter more email ids (like 500+) then program show time out error.
can any one please solve this problem.
we have to use TO,Cc,BCc,Subject and then Message in HTML Format. All these are entered manually by the user, not from the database.I send emails using SMTP server, I've my own SMTP server.
Posted
Comments
AnvilRanger 11-Dec-14 10:59am    
Care to share your code, logging, or error messages you are getting? We cannot help you without seeing what you are doing.

If a small batch of emails are being sent correctly you might now be releasing object from memory and with the higher number of emails you are running out.

1 solution

check this tutorial: Send Bulk (Mass) Email in ASP.Net using C# and VB.Net[^]
it sends emails using parallel multi threading.
sample code:
C#
Parallel.ForEach(dtCustomers.AsEnumerable(), row =>
    {
        SendEmail(row["Email"].ToString(), subject, string.Format(body, row["Name"]));
    });

method:
private bool SendEmail(string recipient, string subject, string body)
{
   bool isSuccess =false;
   try{
    MailMessage mm = new MailMessage("sender@gmail.com", recipient);
    mm.Subject = subject;
    mm.Body = body;
    mm.IsBodyHtml = true;
    SmtpClient smtp = new SmtpClient();
    smtp.Host = "smtp.gmail.com";
    smtp.EnableSsl = true;
    NetworkCredential NetworkCred = new NetworkCredential();
    NetworkCred.UserName = "sender@gmail.com";
    NetworkCred.Password = "<password>";
    smtp.UseDefaultCredentials = true;
    smtp.Credentials = NetworkCred;
    smtp.Port = 587;
    smtp.Send(mm);
    isSuccess =true;
    }catch(Exception ex)
    {
       // log the exception 
       
    }
    return isSuccess ; 
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900