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 7520061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:00:08+00:00 2026-05-30T02:00:08+00:00

I need to develop a mailing system in the intranet web-based application that I

  • 0

I need to develop a mailing system in the intranet web-based application that I am working on it for my company. I am developing it with ASP.NET and C#. The purpose of this system is to let the admin to be able to send emails to the users. I developed this system and I tested for 25 users and it works fine.

Now, I have 386 users in the database, so when I tried to send them emails, I got the following error:

Exception Details: System.Net.Mail.SmtpException: The operation has
timed out.
I think this is because of ISP in my company blocked sending email to many users after a certain number of milliseconds. I tried to use SendAsync but I found it will not benefit me.

Also, I tried to maximize the execution timeout in the Web.config file as folloiwng:

<location path="Email4.aspx">
        <system.web>
                <httpRuntime executionTimeout="180"/>
        </system.web>
</location>

but I failed. So how to fix this problem?

My Code-Behind (C#):

protected void Page_Load(object sender, EventArgs e)
    {
        SendEmailTOAllUser();
    }


    protected void SendEmail(string toAddresses, string fromAddress, string MailSubject, string MessageBody, bool isBodyHtml)
    {
        SmtpClient sc = new SmtpClient("MAIL.companyDomainName.com");
        try
        {
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress("pssp@companyDomainName.com", "PMOD Safety Services Portal (PSSP)");

            // In case the mail system doesn't like no to recipients. This could be removed
            //msg.To.Add("pssp@companyDomainName.com");

            msg.Bcc.Add(toAddresses);
            msg.Subject = MailSubject;
            msg.Body = MessageBody;
            msg.IsBodyHtml = isBodyHtml;
            //Response.Write(msg);
            sc.Send(msg);
        }
        catch (Exception ex)
        {
            throw ex;
        }

    }

    protected void SendEmailTOAllUser()

    {
        string connString = "Data Source=localhost\\sqlexpress;Initial Catalog=psspEmail;Integrated Security=True";

        using (SqlConnection conn = new SqlConnection(connString))
        {
            var sbEmailAddresses = new System.Text.StringBuilder(1000);
            string quizid = "";

            // Open DB connection.
            conn.Open();

            string cmdText = "SELECT MIN (QuizID) As mQuizID FROM dbo.QUIZ WHERE IsSent <> 1";
            using (SqlCommand cmd = new SqlCommand(cmdText, conn))
            {
                SqlDataReader reader = cmd.ExecuteReader();
                if (reader != null)
                {
                    while (reader.Read())
                    {
                        // There is only 1 column, so just retrieve it using the ordinal position
                        quizid = reader["mQuizID"].ToString();

                    }
                }
                reader.Close();
            }

            string cmdText2 = "SELECT Username FROM dbo.employee";
            using (SqlCommand cmd = new SqlCommand(cmdText2, conn))
            {
                SqlDataReader reader = cmd.ExecuteReader();
                if (reader != null)
                {
                    while (reader.Read())
                    {
                        var sName = reader.GetString(0);
                        if (!string.IsNullOrEmpty(sName))
                        {
                            if (sbEmailAddresses.Length != 0)
                            {
                                sbEmailAddresses.Append(",");
                            }
                            // Just use the ordinal position for the user name since there is only 1 column
                            sbEmailAddresses.Append(sName).Append("@companyDomainName.com");
                        }
                    }
                }
                reader.Close();
            }

            string cmdText3 = "UPDATE dbo.Quiz SET IsSent = 1 WHERE QuizId = @QuizID";
            using (SqlCommand cmd = new SqlCommand(cmdText3, conn))
            {
                // Add the parameter to the command
                var oParameter = cmd.Parameters.Add("@QuizID", SqlDbType.Int);
                // Get a local copy of the email addresses
                var sEMailAddresses = sbEmailAddresses.ToString();


                    string link = "<a href='http://startQuiz.aspx?testid=" + quizid + "'> Click here to participate </a>";
                    string body = @"Good day, <br /><br />
                                <b> Please participate in the new short safety quiz </b>"
                                        + link +
                                        @"<br /><br />


                    SendEmail(sEMailAddresses, "", "Notification of New Weekly Safety Quiz", body, true);

                    // Update the parameter for the current quiz
                    oParameter.Value = quizid;
                    // And execute the command
                    cmd.ExecuteNonQuery();
            }
            conn.Close();
        }
    }
  • 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-30T02:00:09+00:00Added an answer on May 30, 2026 at 2:00 am

    Here is how you can split the list: (Please notes that this is pseudo code, i have not tested it)
    Also, this will send an email per five users. You can increase the amount as you please.

    var sEMailAddresses = sbEmailAddresses.ToString();
    string link = "<a href='http://pmv/pssp/StartQuiz.aspx?testid=" + quizid + "'> Click here to participate </a>";
    string body = @"Good day, <br /><br />
                                    <b> Please participate in the new short safety quiz </b>"
                        + link +
                        @"<br /><br />
                                Also, give yourself a chance to gain more safety culture by reading the PMOD Newsletter.
                                <br /> <br /><br /> <br />
                                This email was generated using the <a href='http://pmv/pssp/Default.aspx'>PMOD Safety Services Portal (PSSP) </a>. 
                                Please do not reply to this email.
                                ";
    
    int sendCount = 0;
    List<string> addressList = new List<string>(sEMailAddresses.Split(','));
    StringBuilder addressesToSend = new StringBuilder();
    
    for (int userIndex = 0; userIndex < addressList.Count; userIndex++)
    {
        sendCount++;
        if (addressesToSend.Length > 0)
            addressesToSend.Append(",");
    
        addressesToSend.Append(addressList[userIndex]);
        if (sendCount == 5 || userIndex == addressList.Count - 1)
        {
            SendEmail(addressesToSend.ToString(), "", "Notification of New Weekly Safety Quiz", body, true);
            addressesToSend.Clear();
            sendCount = 0;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to develop a generic jQuery-based search plugin for the ASP.NET MVC application
I need to develop web application using ASP.net with C# to handle mysql database
I need to develop a windows application with .NET 3.5 that needs to have
I need to develop own .NET off-line application which will just open a web
I need to develop a browser based application that record the user screen, much
I need to develop a classic asp application on vista, and would like to
I need to develop a lightweight web application, it will: have a simple webgui
I need to develop a server side application that opens sockets and manages communication
I'm looking for a java-based (preferable) mailing list application that allows users to opt-in/opt-out
I need to develop an application that will check whether the phone is in

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.