Question

Long time reader, first-time asker.

I get a time-out when sending email to 110 BCC recipients.

I'm trying to send a single email message from a website to members of my club whose website I run. I add myself as the sender and receiver, and the members' email addresses go in the BCC list. There are about 110 members. I authenticate against the server with the sender's username and password.

I can prepare the MailMessage just fine, but when I call SmtpClient.Send() it times-out, even with a threshold of 10 minutes. When there are fewer recipients, the Send() method still takes ages (5-7 minutes) but completes successfully. This happens regardless of the size of the message or attachments, even with no attachments.

I think that my mail server (on my hosted web server) is somehow checking each recipient email address against an external system such as a spam/blacklist or against each recipient mail server.

My hosting company is stumped, they swear blind that it's all OK.

Do you know of a member on StmpClient or MailMessage that I can set to tell the mail server not to do this? Or perhaps (even better) as setting in the Parallels HSPhere email server to stop this action?

Many thanks in advance.

Sample code

bool SendEmail(string[] emailAddresses)
{
    MailMessage message = new MailMessage();
    SmtpClient smtp = new SmtpClient("mail.myServer.org");
    message.From = new MailAddress("website@myServer.org", "Display name");
    message.To.Add("website@myServer.org");

    foreach (string recipient in emailAddresses)
    {
        // ABout 110 recipients
        message.Bcc.Add(recipient);
    }

    message.Subject = "Whatever";
    message.ReplyTo = new MailAddress("myOtherEmailAddress@external.com");
    smtp.Credentials = new NetworkCredential(message.From.Address, "whatever");

    try
    {
        message.Body = "A few hundred bytes";
        smtp.Timeout = 300000; // 10 mins
        smtp.Send(message);
    }
    catch (Exception ex)
    {
        // Report here
    }

    return true;
}
Was it helpful?

Solution

The resolution to this question is DNS checking. My outbound email server took each address on the recipients list and attempted to look-up in DNS the MX record for their domain.
For 110 addresses there were several score different domains, and this look-up took a long time. It did this While-U-Wait, and either my browser gave up waiting on the webserver or the webserver gave up waiting on the mail server (can't remember which now).

My provider has since disabled this option.

While waiting for them to acknowledge the problem, I solved it in the following way. Instead of sending one email with 110 recipients, I stored the details of what I wanted to send in two tables - one row for the body, another 110 rows for the recipients. Another ASP page then polled this table, selecting 10 queued emails at a time, sent them, and printed HTML to refresh itself after a few seconds. Having created my rows in one page, I clicked to the sending page and waited a few minutes while it batched. The total time is the same, probably more, but the smaller batches meant nothing timed-out.

Hope that helps the next person.

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