I'm not entirely sure what I'm doing. But this is what I have so far but I'm not sure how to get it to check a file for the date. As well as a lot of other things.
'Option Strict On Option Explicit On Imports System Imports System.Data.SqlClient Imports System.Web.Mail Imports System.Web.Mail.MailMessage Imports System.Timers Public Class Timer1 Dim aTimer As New System.Timers.Timer() aTimer.Interval = 86400000 aTimer.Enabled = True GC.KeepAlive(aTimer) End Class Partial Class EmailAll Inherits System.Web.UI.Page Protected Sub EmailReminder() Dim conn As New SqlConnection("Data Source=IT-P02\SQLEXPRESS;Initial Catalog=EmailReminder;Integrated Security=True") Dim cmd As New SqlCommand("SELECT Email, FullName, Printer, 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 = New MailMessage() Dim emailbody As String = "" Try conn.Open() reader = cmd.ExecuteReader() If reader.HasRows Then While reader.Read() Try MyMail = New MailMessage() MyMail.From = "email@example.com" MyMail.To = reader("Email") MyMail.Subject = "Meter Reading Reminder" MyMail.Body = emailbody & "Dear " & reader("FullName") & ", this is your reminder to report your meter reading for your " & reader("Printer") & _ ". You can report it at http://www.hackworthimaging.com/meterreading.asp" MyMail.BodyEncoding = Encoding.ASCII MyMail.BodyFormat = MailFormat.Text MyMail.Priority = MailPriority.Normal SmtpMail.SmtpServer = "localhost" 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 End Sub End Class
The timer doesn't do anything for you unless you specify what it should call when the interval lapses.
Otherwise, make sure you do not have to declare GC as well.
Yeah, that wasn't a finished product. I just wasn't sure what comes next. I'm guessing it supposed to call the file that holds the email dates, which I do not have as of yet. What is supposed to be holding that?
No, it calls the function on the same page.
Set the interval and target it to the function. It will automatically run the function.
Do, I need to have an array with the different dates? Excuse me if sounds like I'm talking out of my butt, because I probably am.