473,387 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Mass Email and Stringbuilder

Ok I don't know what is the problem with my code But I am trying to build a
newsletter that gathers parameters from 3 textbox controls and a Listbox
control. The form then queries the event table based on 2 of the textboxes
one for the start date of the events required and one for the last date of
the events required. The 3rd textbox works fine. It passes the text from the
textbox to the stringbuilder I built on the codebehind just fine. As well the
Listbox works as expected. The problem I am having is with the Events table
described earlier.

I set an event to iterate through the rows in the Event Table and stuff the
information into a String. This string is then appended to the StringBuilder
to add to the email message.

The Problem:

WHen the I iterate through the Event Table in the dataset it doesn't stop
reading one row when there is one row to read. It keeps reading the same row
over and over again. I can't explain it. I think it repeatadly loops
through the data for every email address table and stuffs the information
into one email.

Below is the Codebehind:

public class EventBroadcast : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Table EBroadcast;
protected System.Web.UI.WebControls.LinkButton ImageAttach;
protected System.Web.UI.WebControls.ListBox IMGList;
protected System.Web.UI.WebControls.TextBox StartDate;
protected System.Web.UI.WebControls.TextBox Message;
protected System.Web.UI.WebControls.TextBox EndDate;

// Event Gathering.
protected System.Data.SqlClient.SqlConnection clubconn;
protected System.Data.SqlClient.SqlDataAdapter clubadapt;
protected System.Data.DataSet dsClub;
protected System.Text.StringBuilder MailString;
protected System.Web.Mail.MailMessage MailSite;
protected System.Data.SqlClient.SqlCommand clubcmd;
protected System.Data.SqlClient.SqlDataReader clubDR;

protected System.Data.SqlClient.SqlDataAdapter clubadapt2;
protected System.Data.DataSet dsClub2;
string strEventRelease;

public string strclubconn
{
get{return ConfigurationSettings.AppSettings["ConnectionString"];}
}
public string EMessage
{
get{return Message.Text.ToString().Replace("\n","<br>");}
}
public string stringpath
{
get{return Server.MapPath(@"..\BroadcastIMG\");}
}
private void Page_Load(object sender, System.EventArgs e)
{
ImageAttach.Attributes.Add("onClick","javascript:w indow.open('../Secured/EmailIMG.aspx','imgWindow','width=700, height=275');");
if(!Page.IsPostBack)
{
GetDirPath(stringpath);
}
}
public void GetDirPath(string path)
{
string[] ImgList=Directory.GetFiles(path);
foreach(string Filename in ImgList)
{
string filename=Path.GetFileName(Filename);
IMGList.Items.Add(filename);
IMGList.DataValueField=path + filename;
IMGList.SelectedIndex=-1;
}
}
protected void Button_Click(object sender, System.EventArgs e)
{
DateTime StDate=System.Convert.ToDateTime(StartDate.Text);
DateTime EnDate=System.Convert.ToDateTime(EndDate.Text);
BindData(StDate,EnDate);

string strEmailSelect="SELECT Test.* FROM Test";
clubconn=new SqlConnection(strclubconn);
clubconn.Open();
dsClub2=new DataSet();
clubadapt2=new SqlDataAdapter(strEmailSelect,clubconn);
clubadapt2.Fill(dsClub2,"Email");
clubconn.Close();
Session["MailBody"]=MailString.ToString();
foreach(DataRow dr1 in dsClub2.Tables["Email"].Rows)
{
BindData(StDate,EnDate);
MailSite=new MailMessage();
MailSite.From="in**@sonar.bc.ca";
MailSite.To=dr1["Email"].ToString();
MailSite.Cc="sa********@shaw.ca";
MailSite.Subject="News Release";
MailSite.BodyFormat=MailFormat.Html;
MailSite.Body=MailString.ToString();
SmtpMail.SmtpServer="smtp.paconline.net";
SmtpMail.Send(MailSite);
}
Response.Redirect("../Secured/MassConfirm.aspx");
}
public string EventList(System.DateTime SDate, System.DateTime EDate)
{
string strEventSelect="SELECT EVNR_tbl.* FROM EVNR_tbl, img_tbl WHERE
EVNR_tbl._Date BETWEEN '" + SDate.ToString("yyyy/MM/dd") + "' AND '" +
EDate.ToString("yyyy/MM/dd") + "' ORDER BY EVNR_tbl._Date ASC";

clubconn=new SqlConnection(strclubconn);
clubconn.Open();
dsClub=new DataSet();
clubadapt=new SqlDataAdapter(strEventSelect,clubconn);
clubadapt.FillSchema(dsClub,SchemaType.Source,"EVN R_tbl");
clubadapt.Fill(dsClub,"EVNR");
foreach(DataRow dr in dsClub.Tables["EVNR"].Rows)
{
strEventRelease += "<br><br>" + System.Convert.ToDateTime(dr["_Date"]) +
" " + dr["EventTitle"] + "<br>";
strEventRelease +=
dr["Description"].ToString().Replace("\n","<br>").Trim() + "<br>";
strEventRelease += "For details press <a
href='http://www.sonar.bc.ca/EventCalendar.aspx'> here </a>" + "<br>";
}
return strEventRelease;
}
public System.Text.StringBuilder BindData(System.DateTime SDate,
System.DateTime EDate)
{
EventList(SDate,EDate);
MailString=new System.Text.StringBuilder(99000);
// Set Email Body.
MailString.Append("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0
Transitional//EN' >");
MailString.Append("<HTML>");
MailString.Append("<HEAD>");
MailString.Append("<meta name='GENERATOR' Content='Microsoft Visual
Studio .NET 7.1'>");
MailString.Append("<meta name='CODE_LANGUAGE' Content='C#'>");
MailString.Append("<meta name='vs_defaultClientScript'
content='JavaScript'>");
MailString.Append("<meta name='vs_targetSchema'
content='http://schemas.microsoft.com/intellisense/ie5'>");
MailString.Append("</HEAD>");
MailString.Append("<body MS_POSITIONING='GridLayout' bgColor='black'>");
MailString.Append("<form id='Form1' method='post' runat='server'>");
MailString.Append("<table borderColor='#ffffff' cellSpacing='0'
cellPadding='0' width='500' align='center' border='1'>");
MailString.Append("<tr>");
MailString.Append("<td>");
MailString.Append("<table cellSpacing='0' cellPadding='0' width='100%'
border='0'>");
MailString.Append("<tr>");
MailString.Append("<td colspan='2'><IMG
SRC='http://www.sonar.bc.ca/images/Header.jpg'></td>");
MailString.Append("</tr>");
MailString.Append("<tr>");
MailString.Append("<td colspan='2' style='HEIGHT: 48px'>");
MailString.Append("<table cellpadding='10' cellspacing='0' border='0'
width='100%'>");
MailString.Append("<tr bgcolor='#000033'>");
MailString.Append("<td style='FONT-SIZE: 10px; COLOR: white; FONT-FAMILY:
Verdana'>" + EMessage + "</td>");
MailString.Append("</tr>");
MailString.Append("</table>");
MailString.Append("</td>");
MailString.Append("</tr>");
MailString.Append("<tr>");
MailString.Append("<td>");
MailString.Append("<table cellpadding='10' cellspacing='0' border='0'
width='100%'>");
MailString.Append("<tr>");
MailString.Append("<td style='FONT-SIZE: 10px; WIDTH: 251px; COLOR:
white; FONT-FAMILY: Verdana' vAlign='Top'>");
MailString.Append(strEventRelease);
MailString.Append("</td>");
MailString.Append("<td style='FONT-SIZE: 10px; COLOR: white; FONT-FAMILY:
Verdana' vAlign='top'>");
MailString.Append("<p>Promotions</p>");
foreach(ListItem i in IMGList.Items)
{
if(i.Selected)
{
MailString.Append("<img src='http://www.sonar.bc.ca/BroadcastIMG/" +
i.Text + "'" + ">" +"<br>");
MailString.Append("<br><hr noshade='true'><br>");
}
}
MailString.Append("</td>");
MailString.Append("</tr>");
MailString.Append("</table>");
MailString.Append("</td>");
MailString.Append("</tr>");
MailString.Append("</table>");
MailString.Append("</td>");
MailString.Append("</tr>");
MailString.Append("</table>");
MailString.Append("</form>");
MailString.Append("</body>");
MailString.Append("</HTML>");

return MailString;
}
}
I know this is a lot to read but, for the life of me, I can't figure out
what is wrong. Please someone help.
Nov 19 '05 #1
0 1473

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jeffrey Silverman | last post by:
Hi, all. Sorry, first off, for the kidna weird selection of crossposted groups, but this question touches on aspects of discussion in each of the groups. So I have a group of around 500 email...
3
by: Strasser | last post by:
In Access2000 mass emailing worked perfectly (very powerful tool!). Doesn't work when using XP version of both Access and Outlook, even though I checked the box to ensure that I was sending the...
3
by: Gil \(Asp.net Developer\) | last post by:
2
by: William Gower | last post by:
I am creating an email message to be sent from a web page. How do I embed variables like strFirstName, strLastName etc. into the body I would like it to say. Last Name : strLastName ...
3
by: ramata | last post by:
Hi I am using StringBuilder to compose an email. The body of email consists of a table for which data has to be taken fron SQL Server. I use append method to add text to the StringBuilder...
5
by: tshad | last post by:
Is there a way to easily put a Datagrid in an email? I want to send a select result in the form of a Datagrid via an email to some of our clients. Thanks, Tom
2
by: Bob Alston | last post by:
I am looking for suggestions for software or access code or utilities to assist in doing mass emailings from an Access database. The emailings would likely be a few thousand at a time. Generally...
1
by: akuva | last post by:
I have to send more than 100s of email using a php code if i use mail function whether it will be sent to spam or inbox. If it is sent to spam which is the other way to send mass email from php. i...
0
by: PokerMan | last post by:
Hi guys Can anyone tell me the best way to implement a mass email newshot, to 1million plus people! I have done this: 1) Set up a news email account on my server 2) Set that email as the...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.