开发者

delay in receiving email sent from c#

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 MailMes开发者_如何学Csage(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


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜