| | |
Auto Email Reminder
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
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?
•
•
Join Date: May 2005
Posts: 514
Reputation:
Solved Threads: 19
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.
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.
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.
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
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.
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.
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
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:
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:
ASP.NET Syntax (Toggle Plain Text)
Dim conn As New SqlConnection( connstring ) Dim cmd As New SqlCommand("SELECT Email, FullName, ReminderID FROM Reminders WHERE Active=1 AND EmailDate<=getdate()", conn) Dim reader As SqlDataReader Dim strIDs As String = "" Dim strIDsFailed As String = "" Dim mymail As MailMessage Try conn.Open() reader = cmd.ExecuteReader() If reader.HasRows Then While reader.Read() Try mymail = New MailMessage() mymail.To = reader("Email") ... mymail.Body = bodyyoucreate & "Dear Mr./Ms. " & reader("FullName") SMTPMail.smtpserver = "" SMTPMail.Send(mymail) strIDs &= "," & reader("ReminderID") Catch strIDsFailed &= "," & reader("ReminderID") End Try End While End If reader.Close() 'You should try looping through this again for all those who failed ("ids") If Len(strIDs) > 0 Then If strIDs.substring(0,1) = "," Then strIDs.Remove(0,1) cmd = New SqlCommand("UPDATE Reminders SET EmailDate=DATEADD(mm, 1, EmailDate) WHERE ReminderID IN (" & strIDs & ")", conn) End If conn.Close() 'might want to write to a text file all the id's that failed to be sent. Catch 'write to a text file about the date this failed. End Try
Last edited by SheSaidImaPregy; Feb 29th, 2008 at 10:49 am.
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
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.
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.
![]() |
Similar Threads
- auto e-mail (Visual Basic 4 / 5 / 6)
- Symantec Proxy Email Messages (Viruses, Spyware and other Nasties)
- Auto call to a servlet file inside Tomcat 4.1 (JSP)
- Symantec Email Proxy!! HELP NEEDED (Viruses, Spyware and other Nasties)
- Symantec Email Proxy problem (Viruses, Spyware and other Nasties)
- Hijacked by about:blank (Viruses, Spyware and other Nasties)
- Unknown Internet Explorer Issue (Viruses, Spyware and other Nasties)
Other Threads in the ASP.NET Forum
- Previous Thread: problem with insert statement
- Next Thread: Javascript Smooth Scrolling
| Thread Tools | Search this Thread |
Tag cloud for ASP.NET
.net 2.0 activexcontrol advice ajax alltypeofvideos anathor application asp asp.net bc30451 bottomasp.net box browser button c# checkbox click commonfunctions confirmationcodegeneration css dataaccesslayer database datagridview datagridviewcheckbox datalist deadlock development dgv dropdownlist dynamically edit expose feedback fileuploader fill flash form formatdecimal forms formview google grid gridview gudi iframe iis javascript jquery listbox login microsoft mono mouse mssql multistepregistration news numerical objects opera panelmasterpagebuttoncontrols parent project radio redirect registration relationaldatabases reportemail richtextbox rotatepage save schoolproject search security select silverlight smartcard smoobjects software sql-server sqlserver2005 suse textbox tracking unauthorized validation vb.net video videos view virtualdirectory vista visualstudio web webapplications webdevelopemnt webprogramming webservice xsl youareanotmemberofthedebuggerusers






