the stored procedure outputs the correct data.. you know what, total records are about 500 and when sending it took long time so i aborted it when it was half through.. just for testing i BCC emails to myself and I found that my email received the message 10,0383 times!!
Just FYI,if you are testing it on the live server,sending so many msges can mark your domain as spam and hence get blocked in the future.I recommend you to test it locally and see if you are still getting that many msges?Also can you reconfirm the RecordCount returned by your stored procedure? Vikram DiscountASP.NET www.DiscountASP.NET
sorry, just used wrong word when i said testing, i mean to make sure all messages will be received successfuly.
Jaz, Not sure what is causing the problem if your stored procedure is outputting the correct information. I put together an application that does what you are attempting to do. Here is a snippet of code that may help you out. I used a dataset to store the output from the stored procedure and then parsed through the dataset. ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["Connection String Name Goes Here"]; SqlConnection conn = new SqlConnection(connectionStringSettings.ConnectionString); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "email_List"; SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; DataSet ds = new DataSet(); da.Fill(ds, "addresses"); foreach (DataRow dr in ds.Tables["addresses"].Rows) { //confirmation sent to the submitter MailMessage email = new MailMessage("[email protected]", dr["emailAddress"].ToString(), tbSubject.Text, tbMessage.Text.ToString()); email.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Send(email); } conn.Close(); Post Edited (Rookie) : 8/6/2007 8:24:16 PM GMT
i tried that code with the dataset and limited the total number of emails to one email only but i am sometimes receieving one message and sometimes two messages 9same message twice).. here is the code: sql_connection = new SqlConnection(ConfigurationManager.ConnectionStrings["website_connectionstring"].ToString()); sql_connection.Open(); MailMessage mail_message = new MailMessage(); SmtpClient smtp_client = new SmtpClient("smtp.zatoor.com"); NetworkCredential network_credential = new NetworkCredential("[email protected]", "xxxxxxx"); smtp_client.UseDefaultCredentials = false; smtp_client.Port = 25; smtp_client.Credentials = network_credential; html_message = "<html>"; html_message += "<head>"; html_message += "<meta http-equiv=Content-Type content='text/html; charset=windows-1252'>"; html_message += "</head>"; html_message += ""; html_message += "<img id'zatoor_logo' alt=' zatoor.com ' src='http://www.zatoor.com/images/common/website_logo.jpg' border='0'>"; html_message += ""; html_message += "Dear members and visitors,"; html_message += "I would like to apologize for the bulk messages you have received last week from zatoor.com which was caused by the email sending method. We have now corrected the problem and again apologize for any inconvenience this may have caused you."; html_message += ""; html_message += "zatoor.com team"; html_message += ""; html_message += ""; html_message += "</body>"; html_message += "</html>"; sql_command = new SqlCommand("sp_send_newsletter", sql_connection); sql_command.CommandType = CommandType.StoredProcedure; sql_adapter = new SqlDataAdapter(); sql_adapter.SelectCommand = sql_command; DataSet data_set = new DataSet(); sql_adapter.Fill(data_set, "members"); foreach (DataRow data_row in data_set.Tables["members"].Rows) { mail_message.From = new MailAddress("[email protected]", "zatoor.com"); mail_message.ReplyTo = new MailAddress("[email protected]"); mail_message.To.Add(data_row["email_address"].ToString()); mail_message.Bcc.Add("[email protected]"); mail_message.Headers.Add("company", "zatoor.com"); mail_message.Priority = MailPriority.Normal; mail_message.IsBodyHtml = true; mail_message.Subject = "apologize from zatoor.com"; mail_message.Body = html_message; smtp_client.Send(mail_message); } sql_connection.Close();
just one note... after 5minutes of sending the emails to the one email and receiveing 2 messages (same message twice), i have just received the same message again though I didn't send it after tha last time (5min back)
I tried sending news letter to about 500 email addres using this code but your server sent the same message hudred times to each email account though the code display each email once only when i execute as response.write. what's the problem? sql_connection = new SqlConnection(ConfigurationManager.ConnectionStrings["website_connectionstring"].ToString()); sql_connection.Open(); MailMessage mail_message = new MailMessage(); SmtpClient smtp_client = new SmtpClient("smtp.zatoor.com"); NetworkCredential network_credential = new NetworkCredential("[email protected]", "xxxxxxxx"); smtp_client.UseDefaultCredentials = false; smtp_client.Port = 25; smtp_client.Credentials = network_credential; html_message = "<html>"; html_message += "<head>"; html_message += "<meta http-equiv=Content-Type content='text/html; charset=windows-1252'>"; html_message += "</head>"; html_message += ""; html_message += ""; html_message += "This message was sent to you by:"; html_message += "<a href='http://www.zatoor.com'>www.zatoor.com</a>"; html_message += ""; html_message += "<a href='http://www.zatoor.com'><img alt=' zatoor.com ' src='http://www.zatoor.com/images/bader.jpg' border='0'></a>"; html_message += ""; html_message += "<a href='http://www.zatoor.com'>http://www.zatoor.com</a>"; html_message += ""; html_message += "</body>"; html_message += "</html>"; sql_command = new SqlCommand("sp_send_newsletter", sql_connection); sql_command.CommandType = CommandType.StoredProcedure; sql_reader = sql_command.ExecuteReader(); if (sql_reader != null) { while (sql_reader.Read()) { mail_message.From = new MailAddress("[email protected]", "zatoor.com"); mail_message.ReplyTo = new MailAddress("[email protected]"); mail_message.To.Add(sql_reader["email_address"].ToString()); // mail_message.To.Add("[email protected]"); mail_message.Bcc.Add("[email protected]"); mail_message.Headers.Add("company", "zatoor.com"); mail_message.Priority = MailPriority.High; mail_message.IsBodyHtml = true; mail_message.Subject = "have you seen bader?"; mail_message.Body = html_message; Response.Write(sql_reader["email_address"].ToString()); // smtp_client.Send(mail_message); } } sql_reader.Close(); sql_connection.Close();
not fixed yet.. thus is the scenario.. I have unique email address. I use the same code to send emails I received duplicate message for each email.
Jaz, I not sure what your last post meant but it sounds like it is working? The duplicate emails you are recieving might be from a duplicate record in the database (maybe, not sure what the data looks like). Are your issues fixed? Rookie
Look at the email header to see if the message ID is the same between the duplicate messages. If they are the same, the email client is downloading it twice. If they are different, the message was sent twice (or multiple times) by the application. Bruce DiscountASP.NET www.DiscountASP.NET
how can i get the message id? here is the full header for two messages.. From zatoor.com Mon Aug 6 16:34:44 2007 Return-Path: <[email protected]> Authentication-Results: mta532.mail.mud.yahoo.com from=; domainkeys=neutral (no sig) Received: from 64.79.170.125 (EHLO outbound-smtp.internetmailserver.net) (64.79.170.125) by mta532.mail.mud.yahoo.com with SMTP; Mon, 06 Aug 2007 16:54:45 -0700 Received: (qmail 17464 invoked from network); 6 Aug 2007 23:34:44 -0000 Received: from web147.discountasp.net (HELO web147) ([email protected]@[209.67.188.8]) (envelope-sender <[email protected]>) by mta00.internetmailserver.net with SMTP for <[email protected]>; 6 Aug 2007 23:34:44 -0000 company: zatoor.com company: zatoor.com mime-version: 1.0 from: zatoor.com <[email protected]> to: [email protected], [email protected] reply-to: [email protected] date: 6 Aug 2007 16:34:44 -0700 subject: apologize from zatoor.com content-type: text/html; charset=us-ascii content-transfer-encoding: quoted-printable Content-Length: 577 From zatoor.com Mon Aug 6 16:34:44 2007 Return-Path: <[email protected]> Authentication-Results: mta170.mail.re3.yahoo.com from=; domainkeys=neutral (no sig) Received: from 64.79.170.125 (EHLO outbound-smtp.internetmailserver.net) (64.79.170.125) by mta170.mail.re3.yahoo.com with SMTP; Mon, 06 Aug 2007 16:34:45 -0700 Received: (qmail 17456 invoked from network); 6 Aug 2007 23:34:44 -0000 Received: from web147.discountasp.net (HELO web147) ([email protected]@[209.67.188.8]) (envelope-sender <[email protected]>) by mta00.internetmailserver.net with SMTP for <[email protected]>; 6 Aug 2007 23:34:44 -0000 company: zatoor.com mime-version: 1.0 from: zatoor.com <[email protected]> to: [email protected] reply-to: [email protected] date: 6 Aug 2007 16:34:44 -0700 subject: apologize from zatoor.com content-type: text/html; charset=us-ascii content-transfer-encoding: quoted-printable Content-Length: 577
i found another problem. You should use "localhost" as your SMTP server rather than smtp.domain.com Bruce DiscountASP.NET www.DiscountASP.NET