tags:

views:

56

answers:

2

The below code works when there are a few element in the "To" list but if i add a large amount, noone recieves the mail . Any clues why this code below would work with a few elments but not with more than one. Also, is there anyway to debug this in terms of actually seeing what is getting sent out from the mail server?

    public static void SendMail(string fromEmailAddress_, string[] toEmailAddress_, string[] ccAddress_, string[] bccAddress_, string subject_, string body_, Attachment[] attachments_)
    {
        MailMessage msg = new MailMessage();
        msg.From = new MailAddress(fromEmailAddress_);
        foreach (string email in toEmailAddress_)
        {
            if (IsValidEmail(email))
            {
                msg.To.Add(new MailAddress(email.Trim()));
            }
        }
        if (ccAddress_ != null)
        {
            foreach (string email in ccAddress_)
            {
                if (IsValidEmail(email))
                {
                    msg.CC.Add(new MailAddress(email.Trim()));
                }
            }
        }

        if (bccAddress_ != null)
        {
            foreach (string email in bccAddress_)
            {
                if (IsValidEmail(email))
                {
                    msg.Bcc.Add(new MailAddress(email.Trim()));
                }
            }
        }

        if (attachments_ != null)
        {
            foreach(Attachment attachment in attachments_)
            {
                msg.Attachments.Add(attachment);
            }
        }

        msg.Subject = subject_;
        msg.Body = body_;
        msg.IsBodyHtml = true;
        msg.Priority = MailPriority.High;

        NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential("[email protected]", "password");
            SmtpClient c = new SmtpClient("mail.salemgolfclub.org");
            c.UseDefaultCredentials = false;
            c.Credentials = basicAuthenticationInfo;
        try
        {
            c.Send(msg);
        }
        catch (Exception)
        {

        }
    }
A: 

You'll need to reduce the number of recipients in each message, and instead send multiple messages. I'm not sure what the maximum is, so that will take some experimenting.

Jon B
+2  A: 

Your problem is most likely due to some security restriction on the mail server, and has nothing to do with how it is implemented in your .Net app. I would check the log files on the server.

If you want to test your mailing code independently from a specific mail server, you could configure your app to store the mails as files on your local hard drive instead. The following config snippet does the trick:

<system.net>
    <mailSettings>
      <smtp deliveryMethod="SpecifiedPickupDirectory">
        <specifiedPickupDirectory pickupDirectoryLocation="c:\some\dir\here"/>
      </smtp>
    </mailSettings>
</system.net>

You need to use the default constructor of SmtpClient for this to work, instead of specifying the server name in the code.

Jonas H
found out i had a 50 recipient limit on the mail server
ooo