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

  • Home
  • SEARCH
  • 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 928307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:59:23+00:00 2026-05-15T19:59:23+00:00

every night i have a trigger that executes asp.net page with method that first

  • 0

every night i have a trigger that executes asp.net page with method that first retrieves from DB users with needed details and then emails them with information they need like ie. users that does not have an image in their profile. Once i get data from DB i build large string with encoded HTML and assign it to MailMessage.Body tag. There are about 20000 users per action/night who get the mail. Stored procedures just get users based on criteria i need nothing to optimize there (after proper indexes been made).

How do i optimize it? Can i create sort of queue in ASP.NET that it will be executed all day long without one time action? Maybe i can use async actions to send few emails per time.

Need advice, if you have question about how i perform each action in order to help me don’t be afraid to ask, i will answer i just don’t know what place in code may interest you.

protected void Page_Load(object sender, EventArgs e)
{
    string type = Request.QueryString["type"];
    string spName = "";
    string message = "";

    switch (type)
    {
        //getUsersWithoutPictures
        case "uwp":
            spName = "getUsersWithoutPictures";
            message = getUsersWithoutPicturesTemplate();
            break;
        //getUsersWithoutText
        case "uwt":
            spName = "getUsersWithoutText";
            message = getUsersWithoutTextTemplate();
            break;
        //getUsersWithoutEnteringWebsiteForTwoWeeks
        case "uwewftw":
            spName = "getUsersWithoutEnteringWebsiteForTwoWeeks";
            message = getUsersWithoutEnteringWebsiteForTwoWeeksTemplate();
            break;
        //getUsersWithoutHobbies
        case "uwh":
            spName = "getUsersWithoutHobbies";
            message = getUsersWithoutHobbiesTemplate();
            break;
        //getUsersWithoutCharateristics
        case "uwc":
            spName = "getUsersWithoutCharateristics";
            message = getUsersWithoutCharateristicsTemplate();
            break;
        //getUsersWithoutActivation
        case "uwa":
            spName = "getUsersWithoutActivation";
            message = getUsersWithoutActivationTemplate();
            break;
        default:
            Response.Write("failure");
            Response.End();
            break;         
    }

    DataTable recipientsList = new DataTable();
    using (SqlConnection cn = cms.connect("someconnectionstring"))
    {
        SqlDataAdapter adp = new SqlDataAdapter(spName, cn);
        adp.SelectCommand.CommandType = CommandType.StoredProcedure;
        adp.Fill(recipientsList);
    }

    foreach (DataRow row in recipientsList.Rows)
    {
        try
        {
            IPHostEntry emailHost = Dns.GetHostEntry(row["email"].ToString().Remove(0, row["email"].ToString().LastIndexOf("@") + 1));
            MailMessage myMessage = new MailMessage(new MailAddress("support@" + row["registratioSite"].ToString()), new MailAddress(row["email"].ToString()));
            myMessage.Subject = "";
            myMessage.Body = getGenericEmailTemplate(AffDomains.getFullDomain(row["registratioSite"].ToString()), message, row["email"].ToString(), row["usernumber"].ToString(), row["nick"].ToString());
            myMessage.IsBodyHtml = true;

            SmtpClient mySmtp = new SmtpClient("mysmtp.server.com");
            mySmtp.Send(myMessage);
        }
        catch (Exception)
        {
        }
    }

    Response.Write("success");
    Response.End();
}

private string getGenericEmailTemplate(string domain, string message, string email, string usernumber, string nick)
{
    return "some html";
}

private string getUsersWithoutPicturesTemplate()
{
    return "some message";
}
private string getUsersWithoutTextTemplate()
{
    return "some message 2";
}
private string getUsersWithoutEnteringWebsiteForTwoWeeksTemplate()
{
    return "some message 3";
}
private string getUsersWithoutHobbiesTemplate()
{
    return "some message 4";
}
private string getUsersWithoutCharateristicsTemplate()
{
    return "some message 5";
}
private string getUsersWithoutActivationTemplate()
{
    return "some message 6";
}
  • 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-15T19:59:24+00:00Added an answer on May 15, 2026 at 7:59 pm

    Some pointers based on your current implementation:

    • Do this once per week. Is your site really so important that the users must be tortured every single night?
    • It looks like you’re going to email each user several times, eg if they don’t have a picture and haven’t entered for two weeks they will get two emails. Combine all the events into one email.
    • Batch your emails into small groups based on which notifications they ought to receive, eg BCC 5 users at a time who don’t have images in their profile.
    • Return only the data you need from the stored procs.
    • Move everything you can outside of the main loop eg creation of the EmailHost, MailMessage object and set the relevant properties inside the loop.

    If you want this solution to scale way beyond its current limits however, you might want to think about some sort of multithreaded (or distrubuted) producer/consumer queue. I won’t elaborate further here – there are plenty of examples on the web.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a job that runs every night to pull xml files from a
I've a .net windows service which generates Lucene search indexes every night. I first
I have a data set that I import into a SQL table every night.
I have a script in PostgreSQL which restores test database from dump every night.
I have an SSIS package that works fine. The package runs every night and
I have an InstallShield (InstallScript) installation, created using IS2009, that's built automatically every night,
I have a shell script that runs every night to backup my EC2 sites
I want to create a job that runs every night. I have a database
I have a job that runs every night. I do my own logging in
I have something that makes a new folder with files in every night. Does

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.