Showing posts with label email. Show all posts
Showing posts with label email. Show all posts

Saturday, March 24, 2012

Please help- can;t stop getting emails!

Ok, this is no good. I wrote an email program and when I tested it it went into some kind of endless loop and now it wont stop emailing. Ive closed the web app and everything and I just keep getting emails. I didnt even run the program very long. Ive gotten over 10,000 emails so far. Does anybody know how to cut off a loop like that???If I see the code, probably I can tell you!

As you said, if it is goine to end less loop, it might send those many emails and that's why you are keep getting emails, eventhough you close the page, what ever the mails sent before will be transfered or sent to the corresponding email through SMTP!
ok, here is my code: (i finally stopped getting emails after receiving about 35,000, literally.)


public void TestGroupEmail()
{
SqlDataReader objDR;

SqlConnection conds = new SqlConnection (ConfigurationSettings.AppSettings["con"]);
SqlCommand cmdNewsletter = new SqlCommand( "Select Email From EmailTest", conds); //there should be about 690 email addresses
conds.Open();
objDR = cmdNewsletter.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

int intSIZE = 50;
int intBLOCK = 0;
Hashtable ht = new Hashtable();

while (objDR.Read())
{
for (int POS = 0; POS <= intSIZE; POS++)
{
intBLOCK += 1;
string strBLOCK = (objDR ["Email"] + ";");
strBLOCK = strBLOCK.Substring(0, strBLOCK.Length -1);
strBLOCK.Trim();

ht.Add(intBLOCK.ToString(), strBLOCK );
}
}

for (int i = 0; i <= ht.Count; i++)
{
System.Web.Mail.MailMessage objEmail = new System.Web.Mail.MailMessage();
objEmail.To = "************";
objEmail.From = "**********";
objEmail.Bcc = ht.Values.ToString();
objEmail.Subject = "This is the Test Email Subject." + ht.Keys.ToString(); //This actually doesnt gove me the value of the keys, either
objEmail.Body = "This is the test email body.";
objEmail.BodyFormat = System.Web.Mail.MailFormat.Html;
System.Web.Mail.SmtpMail.SmtpServer = "localhost";
System.Web.Mail.SmtpMail.Send(objEmail);
objEmail = null;
}

}


I took off the emails and just ran a response.write, ht.Count and it gave me 34,782

Thats a huge number of values/ I cant figure out why its like that...
Hint: Approximately 690 possible EMail addresses * 50 = 34,500

Solution: Look VERY carefully at whats happening during the inner loop on POS. Rather than getting up to fifty different EMails on the BCC line of each EMail, you are getting 50 duplicates of each and every EMail added to the hashtable. Note also that your string concatination of multiple EMail addresses (which are actually all the same) separated by semi-colons is not working either either as a new strBlock is created each time through the inner loop.

As far as code added to the EMail subject for debugging, I'm not sure that Keys.ToString is even defined as a valid method. It most likely does not produce a string containing a list of the hashtable keys.
How many records are in the database?

Also for each record you are looping through 51 times, means you migh have more than 682 records in DB, each record you are counting 51 times, that's why you are getting 34,782 as count!!!

I was not sure why you are adding each record 51 times to the ht table?
If you have 682 records in that table, then that's why you are getting that much count!!!

Wednesday, March 21, 2012

Please help me format my email!

Well I guess they say third times a charm so this is the third time Ive posted here and maybe someone will reply..
OK First off two things you should know:
1) This is my first ever .NET Website. Ever.
2) I'm using Visual Studio .NET 2003 with SQL Server 2000 deveoped under Windows 2000. The site is hosted under Windows Server 2003 so therefore I cannot test the email functionality in my dev environment because it does not support the email method that 2003 Server does...

Any way, I have a page where users send me an Email which contains data taken from their profiles. When I get it, it looks like this:

Web Part Request: Thursday, December 11, 2003 - 7:53:06 AM 1986 Mercedes-Benz 300E Engine: 6 Tran: A Turbo: N A/C: Y Fourwheel: 2 -------------------- I sent disc brakes back friday the 5th through u.s.p.s. for exchange for correct size .I also need timing chain tensioner,I have a timing chain and link and a gasket.

How can I format the email so its not so confusing? I need it to look like this:

Web Part Request: Thursday, December 11, 2003 - 7:53:06 AM
1986 Mercedes-Benz 300E
Engine: 6
Tran: A
Turbo: N
A/C: Y
Fourwheel: 2
--------------------
I sent disc brakes back friday the 5th through u.s.p.s. for exchange for correct size .I also need timing chain tensioner,I have a timing chain and link and a gasket.

Thanks a lot for your time!
Regards,
Joe

Here is the snippet of code for the page and in case you're wondering, I didnt write this part (hence the reason Im asking for help, a coworker who is no longer here set up the basics):


If Not IsPostBack Then

Dim sessionmember As diyauto.diymember.diymemberdetail = New diyauto.diymember.diymemberdetail
sessionmember = Session("userinfo")

If sessionmember Is Nothing Then
Session("loginreturnpage") = "/partfinder/partrequest.aspx"
Response.Redirect(ConfigurationSettings.AppSettings("SiteHomePage") + "/member/loginagain.aspx")
End If

' show the user name
lblName.Text = Trim(sessionmember.firstname) & " " & (Trim(sessionmember.middlename) & " ") & Trim(sessionmember.lastname)

Dim carid As Integer
carid = Val(Request.QueryString.Get("c"))

If carid = 0 Then
Response.Redirect("partlocator.aspx")
End If

Dim carfunct As diymember.diymembercarfunctions = New diymember.diymembercarfunctions
Dim mycar As diymember.diymembercardetail = New diymember.diymembercardetail

mycar = carfunct.carinfoget(sessionmember.memberid, carid)

'if there is nothing here - send them back!
'Response.Redirect("partlocator.aspx")
If mycar Is Nothing Then
Response.Redirect("partlocator.aspx")
End If

lblCarInfo.Text = mycar.year.ToString + " - " + RTrim(mycar.makename) + " " + RTrim(mycar.modelname) + " Engine: " + mycar.engine + " Tran: " + mycar.autotransmission + " Turbo: " + mycar.turbo + " A/C: " + mycar.aircondit + " Fourwheel: " + mycar.fourwheel + " VIN: " + RTrim(mycar.vin)
hidlabCarInfo.Text = mycar.year.ToString + " " + RTrim(mycar.makename) + " " + RTrim(mycar.modelname) + vbCr + "Engine: " + mycar.engine + vbCr + "Tran: " + mycar.autotransmission + vbCr + "Turbo: " + mycar.turbo + vbCr + "A/C: " + mycar.aircondit + vbCr + "Fourwheel: " + mycar.fourwheel + vbCr + "VIN: " + RTrim(mycar.vin)

End If

End Sub

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

If Len(LTrim(RTrim(tbxRequest.Text))) = 0 Then
lblError.Text = "Please indicate the parts you're Looking for!"
Return
End If

Dim sessionmember As diyauto.diymember.diymemberdetail = New diyauto.diymember.diymemberdetail
sessionmember = Session("userinfo")

If sessionmember Is Nothing Then
Session("loginreturnpage") = "/member/myaccount.aspx"
Response.Redirect(ConfigurationSettings.AppSettings("SiteHomePage") + "/member/loginagain.aspx")
End If

' lets prepare an e-mail and send it along to the parts folks!

Dim Maildiy As New System.Web.Mail.MailMessage
Maildiy.From = RTrim(sessionmember.email)
Maildiy.To = "joe@dotnet.itags.org.diyautoparts.com"
Maildiy.Subject = "WEBSITE PARTS REQUEST"
Maildiy.BodyFormat = Mail.MailFormat.Text
Maildiy.Body = "Web Part Request: " + DateTime.Now.ToLongDateString + " - " + DateTime.Now.ToLongTimeString + vbCr + vbCr + hidlabCarInfo.Text + vbCr + vbCr + "--------------------" + vbCr + vbCr + RTrim(tbxRequest.Text)
System.Web.Mail.SmtpMail.Send(Maildiy)
Maildiy = Nothing

' send an e-mail to the sender!
Dim MailCust As New System.Web.Mail.MailMessage
Dim replytext As String

MailCust.From = "parts@dotnet.itags.org.diyautoparts.com"
MailCust.To = RTrim(sessionmember.email)
MailCust.Subject = "DIYAUTOPARTS.COM - Part Request from Website"
'replytext = "Thank you for requesting car part information from DiyAutoparts.com. Your request has been entered into our system and we will contact you as soon as we have information for you." + vbCr + vbCr + "Our office hours are Monday - Friday 8:00am - 4:30pm EST." + vbCr + vbCr
'replytext += "Web Request time: " + DateTime.Now.ToLongDateString + " - " + DateTime.Now.ToLongTimeString + vbCr + vbCr
'replytext += hidlabCarInfo.Text + vbCr + vbCr + "------------------" + vbCr + vbCr + RTrim(tbxRequest.Text) + vbCr

MailCust.BodyFormat = Mail.MailFormat.Text

MailCust.Body = "Thank you for requesting car part information from DiyAutoparts.com. Your request has been entered into our system and we will contact you as soon as we have information for you." + vbCr + vbCr + "Our office hours are Monday - Friday 8:00am - 4:30pm EST." + vbCr + vbCr
MailCust.Body += "Web Request time: " + DateTime.Now.ToLongDateString + " - " + DateTime.Now.ToLongTimeString + vbCr + vbCr
MailCust.Body += hidlabCarInfo.Text + vbCr + vbCr + "------------------" + vbCr + vbCr + RTrim(tbxRequest.Text) + vbCr

'MailCust.Body = replytext
System.Web.Mail.SmtpMail.Send(MailCust)
MailCust = Nothing

Response.Redirect("partlocatorsub.aspx")

End Sub

Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click
Response.Redirect("partlocator.aspx")
End Sub

Private Sub btnMyAcct_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMyAcct.Click
Response.Redirect(ConfigurationSettings.AppSettings("SiteHomePage") + "/member/myaccount.aspx")
End Sub
End Class

How about just adding some vbCrLf characters in there where you want the line breaks?