Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7673503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:31:35+00:00 2026-05-31T16:31:35+00:00

I just need help. Basically I am creating a windows appllication that sends bulk

  • 0

I just need help. Basically I am creating a windows appllication that sends bulk emails to our customers. the field “email” and “attachment” are from database. the attachment field contains only the path where the file is located, The code is working but instead of receiving 5 emails , I receive 15 emails.

Note: my database contain only 5 records , therefore I should receive only 5 emails with attachments:

Can you help me please, Thanks!

Here is my code:

        string email;
        string attachment;
        ArrayList emailList = new ArrayList();
        ArrayList attachList = new ArrayList();
        private static readonly Logger log = new _EventLogger();

        private void btnSend_Click(object sender, EventArgs e)
        {
            conn.Open();
            SqlCommand cmdgetEmail = new SqlCommand("Select EMAIL, PATH from MEMBERREQUIREMENTS WHERE STATUS=0", conn);
            SqlDataReader getEmail = cmdgetEmail.ExecuteReader();
            //count = 0;
            while (getEmail.Read())
            {
                //count++;
                //email = getEmail.GetValue(i).ToString();
                //emailList.Add(email);
                //i = i + 1 - 1;
                email = getEmail.GetString(0);
                emailList.Add(email);
                attachment = getEmail.GetString(1);
                attachList.Add(attachment);
            }
            getEmail.Close();
            conn.Close();
            sendMail();
        }
            private void sendMail()
            {

                string from="myemail@email.com";
                foreach (string sendTo in emailList)
                {

                    foreach (string sendAttachments in attachList)
                    {
                    MailMessage mail = new MailMessage();
                    mail.To.Add(sendTo);
                    mail.From = new MailAddress(from, "Company Name'", Encoding.UTF8);
                    mail.Subject = subject;
                    mail.Body = msgBodyHead + msgBodyHead2 + msgDate + msgGreet + msgBody + msgAdobe + msgAssistance + msgCompliment + msgfooter;
                    mail.IsBodyHtml = true;
                    mail.Priority = MailPriority.High;    
                    mail.Attachments.Add(new Attachment(sendAttachments));

                        SmtpClient client = new SmtpClient();
                        client.Credentials = new System.Net.NetworkCredential(from, "password");
                        client.Host = "192.167.89.0";
                        client.EnableSsl = false;
                        try
                        {

                            progress();
                            client.Send(mail);

                        }

                        catch (Exception ex)
                        {
                            ProgressBar1.Visible = false;
                            timer1.Enabled = false;
                            Exception excpt = ex;
                            string errorMessage = string.Empty;

                            while (excpt != null)
                            {

                                errorMessage += excpt.ToString(); excpt = excpt.InnerException;
                                log.Error("Email - LMS Application Error", ex);
                                lblError.Text = "There was an error occured while processing your request.\n Please see Event Viewer for more details.";
                                lblError.ForeColor = System.Drawing.Color.Red;
                            }
                        }

                    }
                }
            }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:31:36+00:00Added an answer on May 31, 2026 at 4:31 pm

    It looks like you’re pulling a bunch of records from your MEMBERREQUIREMENTS table containing an email address and a path to an attachment, and building a list of e-mail addresses and attachment paths.

    You’re then iterating over these sending, sending an e-mail for each combination of address and attachment. I’m guessing this is not what you want to do.
    I imagine that either:

    • each recipient should receive only the attachment listed in their record. In this case, you don’t want to iterate over attachments for each address, or possibly
    • each recipient should receive each attachment, but the attachments should be listed in a separate table, and not stored in the record for each address in your MEMBERREQUIREMENTS table.

    UPDATE:

    Below is some code to do the former. Note that this is just a minimal edit of your posted code, and doesn’t fix variable names etc. or provide any additional error checking (which you probably want to do):

    private static readonly Logger log = new _EventLogger();
    
    
    private void btnSend_Click(object sender, EventArgs e)
    {
        conn.Open();
        SqlCommand cmdgetEmail = new SqlCommand("Select EMAIL, PATH from MEMBERREQUIREMENTS WHERE STATUS=0", conn);
        SqlDataReader getEmail = cmdgetEmail.ExecuteReader();
        while (getEmail.Read())
        {
            email = getEmail.GetString(0);
            attachment = getEmail.GetString(1);
            this.sendMail(email, attachment)
        }
        getEmail.Close();
        conn.Close();
    }
    
    private void sendMail(string sendTo, string sendAttachments)
    {
        MailMessage mail = new MailMessage();
        mail.To.Add(sendTo);
        mail.From = new MailAddress(from, "Company Name'", Encoding.UTF8);
        mail.Subject = subject;
        mail.Body = msgBodyHead + msgBodyHead2 + msgDate + msgGreet + msgBody + msgAdobe + msgAssistance + msgCompliment + msgfooter;
        mail.IsBodyHtml = true;
        mail.Priority = MailPriority.High;
        mail.Attachments.Add(new Attachment(sendAttachments));
    
        SmtpClient client = new SmtpClient();
        client.Credentials = new System.Net.NetworkCredential(from, "password");
        client.Host = "192.167.89.0";
        client.EnableSsl = false;
        try
        {
    
            progress();
            client.Send(mail);
    
        }
    
        catch (Exception ex)
        {
            ProgressBar1.Visible = false;
            timer1.Enabled = false;
            Exception excpt = ex;
            string errorMessage = string.Empty;
    
            while (excpt != null)
            {
    
                errorMessage += excpt.ToString(); excpt = excpt.InnerException;
                log.Error("Email - LMS Application Error", ex);
                lblError.Text = "There was an error occured while processing your request.\n Please see Event Viewer for more details.";
                lblError.ForeColor = System.Drawing.Color.Red;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just need some help/advice with SQL Server 2005 and Visual Studio 2005. Basically I
I got some code off the Internet and now I just need help to
I need some help with jQuery script again :-) Just trying to play with
I'm just starting out with the whole ajax thing and I need some help.
Just need a little bit of Javascript to warn people that press the back
So I'm creating a very basic python game and I need some help with
I just need some quick help on syntax. I'm doing a WPF project and
I need help building a loop in my stored procedure, basically i want it
I need help with a regular expression that will find matches in the strings
I need help with binding back after I unbind an element. Basically, I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.