Auto Email Reminder

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2008
Posts: 179
Reputation: foundsheep is an unknown quantity at this point 
Solved Threads: 0
foundsheep's Avatar
foundsheep foundsheep is offline Offline
Junior Poster

Auto Email Reminder

 
0
  #1
Feb 28th, 2008
I have a form that is classic asp that basically collects some info and sends it to an email account. What I really to do is have an email reminder option added. The form is a monthly report and the idea is to have an option for the reminder. The email will be sent monthly. There are other things, but that's all for now. Can this all be done in SQL? And how would that work if so?
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 514
Reputation: techniner is an unknown quantity at this point 
Solved Threads: 19
techniner techniner is offline Offline
Posting Pro

Re: Auto Email Reminder

 
0
  #2
Feb 28th, 2008
I would cron/schedule a job to run a new program.

The new program should read through the member db. Then look at the last email sent date (you will create this field). Now do now() +30 days. If last email > now() - 30 days sent date send an email.
*You could also use BETWEEN and I recommend you do to be 100% sure.

Then flag the DB that an email has been sent and update the last email sent date.

Next time the program runs say midnight the next day ti will not send the ones form the previous day unless it meets 30 day criteria.

This can be done very easily in MSQL.

As a matter of fact if you have MSSQL Enterprise manager you can create this all in a single DTS job and run the email function out of the DTS job as well and then schedule the DTS job.
Last edited by techniner; Feb 28th, 2008 at 9:58 pm.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 179
Reputation: foundsheep is an unknown quantity at this point 
Solved Threads: 0
foundsheep's Avatar
foundsheep foundsheep is offline Offline
Junior Poster

Re: Auto Email Reminder

 
0
  #3
Feb 29th, 2008
This sounds good. One issue is that there is no member db. At this point there is not a good reason to create a full fledged membership. The reminder is for the customer to come back to the site and report a meter reading off their printer. I'm thinking I'll just do a separate form to sign up for reminders, then I'll take care of updating the db myself. Anyway, is there some documentation on how to set this up in SQL? I'm using Express. I have very little experience in this area. Thanks.
Last edited by foundsheep; Feb 29th, 2008 at 9:08 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Auto Email Reminder

 
0
  #4
Feb 29th, 2008
I would do this:

Create a job that sends a page hit to a certain page, let's say emailall.aspx (where it is unable to be seen from an http_referrer.

On the emailall.aspx page, it should search the database and retrieve all records that have the new field that is NOT null: fieldname: EmailDate.

Then grab all records that have the correct email date (today). Attach it to a datareader, and loop through an email function to email those who wish to be reminded. After that, have it UPDATE all the records with the month format:

UPDATE Reminders SET EmailDate=DATEADD(mm, 1, EmailDate) WHERE EmailDate=getdate()

This way you are not searching every record, reformatting it, then searching it again for proper dates.

The problem with "email > now() - 30", besides not being correct format for MS SQL, is that it first searches for all records that are greater than "now()", then reformats all those records to be now() - 30, then searches the string again for the corresponding dates. This is a very harsh task for the server to do, and can take awhile depending on the number of records you have.

By asking for the date to be equal to today, it does 1 search to grab todays date. Any that equal it, OKAY SEND! if not, oh well, better luck next time.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 179
Reputation: foundsheep is an unknown quantity at this point 
Solved Threads: 0
foundsheep's Avatar
foundsheep foundsheep is offline Offline
Junior Poster

Re: Auto Email Reminder

 
0
  #5
Feb 29th, 2008
Is that a nix on using DTS then? I just spent the last hour trying to download it. Hope I can use it.

What is firing the emailall.aspx page? I'm guessing some code I'm not aware of.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Auto Email Reminder

 
0
  #6
Feb 29th, 2008
Don't forget to do a try catch for every single one, or do "on error resume next", however that is greatly depreciated and obsolete (but still works).

You would hate to throw an error half way through and half of the records don't viewed, and none will be updated.

It will be a hefty process, but that's why you do it during "downtimes" or on a separate server.

Something would be like this:
  1. Dim conn As New SqlConnection( connstring )
  2. Dim cmd As New SqlCommand("SELECT Email, FullName, ReminderID FROM Reminders WHERE Active=1 AND EmailDate<=getdate()", conn)
  3. Dim reader As SqlDataReader
  4. Dim strIDs As String = ""
  5. Dim strIDsFailed As String = ""
  6. Dim mymail As MailMessage
  7.  
  8. Try
  9. conn.Open()
  10. reader = cmd.ExecuteReader()
  11.  
  12. If reader.HasRows Then
  13. While reader.Read()
  14. Try
  15. mymail = New MailMessage()
  16. mymail.To = reader("Email")
  17. ...
  18. mymail.Body = bodyyoucreate & "Dear Mr./Ms. " & reader("FullName")
  19. SMTPMail.smtpserver = ""
  20. SMTPMail.Send(mymail)
  21. strIDs &= "," & reader("ReminderID")
  22. Catch
  23. strIDsFailed &= "," & reader("ReminderID")
  24. End Try
  25. End While
  26. End If
  27.  
  28. reader.Close()
  29.  
  30. 'You should try looping through this again for all those who failed ("ids")
  31.  
  32. If Len(strIDs) > 0 Then
  33. If strIDs.substring(0,1) = "," Then strIDs.Remove(0,1)
  34. cmd = New SqlCommand("UPDATE Reminders SET EmailDate=DATEADD(mm, 1, EmailDate) WHERE ReminderID IN (" & strIDs & ")", conn)
  35. End If
  36. conn.Close()
  37.  
  38. 'might want to write to a text file all the id's that failed to be sent.
  39. Catch
  40. 'write to a text file about the date this failed.
  41. End Try
Last edited by SheSaidImaPregy; Feb 29th, 2008 at 10:49 am.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 179
Reputation: foundsheep is an unknown quantity at this point 
Solved Threads: 0
foundsheep's Avatar
foundsheep foundsheep is offline Offline
Junior Poster

Re: Auto Email Reminder

 
0
  #7
Feb 29th, 2008
Ok, I'm going to up the db and go from there.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Auto Email Reminder

 
0
  #8
Feb 29th, 2008
Or what you can do, which would be a better bet cause it would leave less time with an open connection, is quickly store each value into an array (multi dimensional), then call it after.

The problem with this approach, you need to connect again to the server to do the update to ensure you don't update all recs, even ones that failed and never received the email.

If that is not an issue, grab all, put it into an array, do an update, then send emails.
Last edited by SheSaidImaPregy; Feb 29th, 2008 at 11:31 am.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 179
Reputation: foundsheep is an unknown quantity at this point 
Solved Threads: 0
foundsheep's Avatar
foundsheep foundsheep is offline Offline
Junior Poster

Re: Auto Email Reminder

 
0
  #9
Feb 29th, 2008
I'm setting up the emailall page with code behind. Is that correct the way you coded it. I'm getting a lot of 'Statement cannot appear outside of a method body' errors popping up in Intellisense.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Auto Email Reminder

 
0
  #10
Feb 29th, 2008
No, that is coded for inline. Therefore it is going to need a lot of "System...." crap.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC