Advertisement

04.04.2008 at 01:55PM PDT, ID: 23297412 | Points: 500
[x]
Attachment Details

how to use implement a 1 sec delay while sending 1000 emails.........

Asked by niceoneishere in Programming for ASP.NET

Tags: asp.net 2.0 and C#

Hello Everyone,
i am very new to asp. with a lot patience and research i have finally wrote some code for sending email in batches........now the problem is i tried playing with System.threading.Thread.Sleep. so that i can insert a time delay of 1 sec between emails........but for some reason it ain't happening......i cant get this thing to work......i dont even get a error message....

but at the same time i dont recieve any emails when i send them..........if i remove the System.threading tag .......everything works fine and i recieve my emails when i send them........all the emails i am using are real email id's. can someone please explain to me or guide where i am making a mistake......i really appreciate it.  Everything is happening on a button Click. i am just posting the code behind

Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
protected void btnsubmit_Click(object sender, EventArgs e)
    {
        string toemail = null;
 
        MailMessage ebatch = new MailMessage();
        SmtpClient mySmtpClient = null;
        OleDbConnection DBConnection = null;
        OleDbCommand DBCommand = null;
        OleDbDataReader Datareader = null;
        string SQLString = null;
        DBConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Server.MapPath("~/App_Data/cust.mdb"));
        DBConnection.Open();
        SQLString = "SELECT EmailID FROM Customers ";
        DBCommand = new OleDbCommand(SQLString, DBConnection);
        Datareader = DBCommand.ExecuteReader();
        while (Datareader.Read())
        {
            toemail = Convert.ToString(Datareader["EmailID"]);
            ebatch.From = new MailAddress("confirmation@testsite.com");
            ebatch.To.Add(toemail);
            ebatch.Subject = "sample message";
            ebatch.Body = "this is a test message";
            // mail server//
 
            mySmtpClient = new SmtpClient(ConfigurationManager.AppSettings["SmtpRelay"]);
            mySmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
            mySmtpClient.UseDefaultCredentials = true;
            try
            {
                mySmtpClient.Send(ebatch);
                Response.Write("&lt;i> Email Sent to  " + toemail + "!</i>");
                System.Threading.Thread.Sleep(1000);
 
            }
            catch (Exception ex)
            {
 
                Response.Write("the following exception occurred:" + ex.ToString());
                // check with InnerException
                while (ex.InnerException != null)
                {
                    Response.Write("--------------");
                    Response.Write("the following InnerException reported:" + ex.InnerException.ToString());
                    ex = ex.InnerException;
 
                }
 
            }
 
        }
 
        Datareader.Close();
        DBConnection.Close();
    }
 
Loading Advertisement...
 
[+][-]04.04.2008 at 02:14PM PDT, ID: 21285699

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.04.2008 at 06:18PM PDT, ID: 21286754

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628