Question

here is my code

for(int i = 0; i < number ; i++)
{
  MailAddress to = new MailAddress(iMail.to);
  MailAddress from = new MailAddress(iMail.from, iMail.displayName);
  string body = iMail.body;
  string subject = iMail.sub;
  oMail = new MailMessage(from, to);
  oMail.Subject = subject;
  oMail.Body = body;
  oMail.IsBodyHtml = true;
  oMail.Priority = MailPriority.Normal;
  oMail.Sender = from;
  s = new SmtpClient(smtpServer);
  s.ServicePoint.ConnectionLeaseTimeout = 0;
  if (s != null)
  {
     s.Send(oMail);
  }
  oMail.Dispose();
  s = null;
}

i am sending over 60,000 email using this code,now my problem some recipient gets email right away but some of them gets after few minutes and some of them gets even after few hours and may be many of them gets lost before reaching to destination. and my This Issue is still unanswered. i really need help in this. i am stuck. thanks

Was it helpful?

Solution

Actually that makes sense. Don’t you think that by sending 60K emails in a very short timeframe your are likely to be considered as a spammer? Delaying the emails like StrongMail does is a good way to prevent you from being banned by the ISPs.

OTHER TIPS

Try the following: your MailMessage needs to be in a using block. Also, you don't need a new SmtpClient for each message. You certainly don't need to set it to null! This is not VB6.

SmtpClient smtpClient = new SmtpClient(smtpServer);
smtpClient.ServicePoint.ConnectionLeaseTimeout = 0;
for (int i = 0; i < number; i++)
{
    MailAddress to = new MailAddress(iMail.to);
    MailAddress from = new MailAddress(iMail.from, iMail.displayName);
    string body = iMail.body;
    string subject = iMail.sub;
    using (MailMessage mailMessage = new MailMessage(from, to))
    {
        mailMessage.Subject = subject;
        mailMessage.Body = body;
        mailMessage.IsBodyHtml = true;
        mailMessage.Priority = MailPriority.Normal;
        mailMessage.Sender = from;
        smtpClient.Send(mailMessage);
    }
}

Suggestion: don't name variables things like oMail. We know it's an object. Most things are. There's nothing special about objects anymore.

the problem isn't likely with your code, but with your SMTP server.

It could be any number of issues, like failing to find MX records in your DNS server (especially if your DNS server is weak, and can't handle the lookups that fast).

I would check your mail server logs, as some indication as to what is happening.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top