C# .NET - Sending auto emails on particular date and time from web app. hosted on remote server

Asked By Pranay on 17-Dec-12 01:55 PM
I have my web application hosted on a remote server. I've to make a functionality where user can set date and time for the email to be sent and require no further user involvement.  This is my first time doing this so I'm wondering what approach should I take. Can I use windows service for this or should I go with sql reporting service to automate the task? Any other options?
Thanks
Aravind Aravind replied to Pranay on 18-Dec-12 11:48 PM
hi 
u can use window service to create a job to execute sql query.
From web page u get the details(date,time,addresses,msg) from user and store in the database.then u create window service to execute the service every 10 secs or ur own specification.

Protected Overrides Sub OnStart(ByVal args() As String)
        Try
            t = New Timer(5000)  '----->every 5 secs
            AddHandler t.Elapsed, AddressOf TimerFired
            With t
                .AutoReset = True
                .Enabled = True
                .Start()
            End With
          '  MsgBox("start")
        Catch obug As Exception
            LogEvent(obug.Message)
            Throw obug
        End Try
    End Sub


    Protected Overrides Sub OnStop()
        Try
            log.WriteEntry("Service Stopping", EventLogEntryType.Information)
            t.Stop()
            t.Dispose()
            MsgBox("stop")
        Catch obug As Exception
            LogEvent(obug.Message)
        End Try
    End Sub

    Private Sub TimerFired(ByVal sender As Object, ByVal e As ElapsedEventArgs)
        Working()
    End Sub

    Private Sub Working()
            
        Dim con As SqlConnection
        con = New SqlConnection("Data Source=(local)\nnnnnn;Initial Catalog=JobScheduler;User ID=jjjjjj;Password=jjjjjjjj")
        Dim query1 As String
        query1 = "Exec [dbo].[GetJobsToRun]"
        con.Open()
        Dim cmd1 As SqlCommand = New SqlCommand(query1, con)
        Dim da1 As New System.Data.SqlClient.SqlDataAdapter(cmd1)
        cmd1.ExecuteNonQuery()
        con.Close()
     
    End Sub
the above code for window service to execute store procedure([dbo].[GetJobsToRun]) .this sp execute every 5 secs.in that sp u have pass all detail like from,to,msg.before u get the details u have to check time and date(with current data and time).in getjobstorun sp u use select query to get details from table.
u can search for how to send mail from sql server.


















































































Pranay replied to Pranay on 19-Dec-12 12:08 PM
Aravind, thanks a lot for your reply. It was very well put. I just found out that my hosting company don't allow windows service on their servers for security reasons......daang......... Any other ideas for the same problem.
Your help is much appreciated.
Pranay replied to Aravind Aravind on 19-Dec-12 12:09 PM
Aravind, thanks a lot for your reply. It was very well put. I just found out that my hosting company don't allow windows service on their servers for security reasons......daang......... Any other ideas for the same problem.
Your help is much appreciated.