locked
(email) scheduler from codeproject, where to put the email part RRS feed

  • Question

  • User507956310 posted

     Hi Guys,

    I was trying to implement the e(vb.net) mail scheduler as
    found on this website http://www.codeproject.com/script/Forums/View.aspx?fid=229682&msg=2293887
    somehow I do not have much success mainly because I do not undertsand
    i.) where to put the code that will send my email
    ii.) if the whole thing starts firing (counting) once my text.aspx has been loaded?


    1. my test.aspx.vb

     

    Partial Class test
        Inherits System.Web.UI.Page
    
    
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Callback()
            Scheduler.Run("test", 1, AddressOf Callback)
            Response.Write("Test")
        End Sub
    
        Private Sub Callback()
            Using obj_file As New IO.FileStream(Server.MapPath("/log.txt"), IO.FileMode.Append, IO.FileAccess.Write)
                Using obj_writer As New IO.StreamWriter(obj_file)
                    obj_writer.WriteLine(Date.Now.ToString)
                End Using
            End Using
        End Sub
    
    
    End Class
    
     





    2.the scheduler class in the App_Code folder:

     
    Imports Microsoft.VisualBasic
    Imports System
    Imports System.Collections
    Imports System.Text.RegularExpressions
    Imports System.Web
    Imports System.Web.Caching
    Imports System.Net.Mail
    
    
    Public Class Scheduler
    
    Private Class CacheItem
    Public Name As String
    Public Callback As Scheduler.Callback
    Public Expires As Date
    Public Cache As Caching.Cache
    Public LastRun As Date
    End Class
    
    Public Delegate Sub Callback()
    
    Private Shared _NumberOfMinutes As Integer = 1 'new
    
    Public Shared Sub Run(ByVal vstr_name As String, ByVal vint_minutes As Integer, ByVal vobj_call As Callback)
    _NumberOfMinutes = vint_minutes 'new
    Run(vstr_name, Date.Now.AddMinutes(vint_minutes), vobj_call)
    End Sub
    
    Public Shared Sub Run(ByVal vstr_name As String, ByVal vobj_expires As Date, ByVal vobj_call As Callback)
    Dim obj_cache As New CacheItem
    obj_cache.Name = vstr_name
    obj_cache.Callback = vobj_call
    obj_cache.Expires = vobj_expires
    obj_cache.Cache = HttpRuntime.Cache
    obj_cache.LastRun = Date.Now
    Run(obj_cache)
    End Sub
    
    Private Shared Sub Run(ByVal vobj_cache As CacheItem)
    If vobj_cache.Cache.Item(vobj_cache.Name) Is Nothing Then
    'vobj_cache.Cache.Add(vobj_cache.Name, vobj_cache, Nothing, vobj_cache.Expires, Nothing, CacheItemPriority.NotRemovable, AddressOf CacheCallback)
    vobj_cache.Cache.Add(vobj_cache.Name, vobj_cache, Nothing, Date.Now.AddMinutes(_NumberOfMinutes), Nothing, CacheItemPriority.NotRemovable, AddressOf CacheCallback) 'new
    End If
    End Sub
    
    Private Shared Sub CacheCallback(ByVal key As String, ByVal value As Object, ByVal reason As System.Web.Caching.CacheItemRemovedReason)
    Dim obj_cache As CacheItem = DirectCast(value, CacheItem)
    If obj_cache.LastRun < Date.Now Then
    If obj_cache.Callback IsNot Nothing Then
    obj_cache.Callback.Invoke()
    End If
    obj_cache.LastRun = Date.Now
    End If
    Run(obj_cache)
    End Sub
    
    End Class 
     

    Monday, November 10, 2008 4:59 AM

Answers

  • User2141697585 posted

    Nice scheduler codes but I dont see any sending mail related such MailAddress, MailMessage, SMTPClient properties. You google these from the net for samples.

    http://www.beansoftware.com/ASP.NET-Tutorials/Send-E-Mail.aspx

    http://www.sitepoint.com/article/sending-email-asp/

    http://www.asp101.com/samples/

    http://www.eukhost.com/forums/f32/send-email-asp-net-2302/

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 10, 2008 5:32 AM

All replies

  • User2141697585 posted

    Nice scheduler codes but I dont see any sending mail related such MailAddress, MailMessage, SMTPClient properties. You google these from the net for samples.

    http://www.beansoftware.com/ASP.NET-Tutorials/Send-E-Mail.aspx

    http://www.sitepoint.com/article/sending-email-asp/

    http://www.asp101.com/samples/

    http://www.eukhost.com/forums/f32/send-email-asp-net-2302/

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 10, 2008 5:32 AM
  • User2141697585 posted

    Nice scheduler codes but I dont see any sending mail related such MailAddress, MailMessage, SMTPClient properties. You can google these from the net for samples.

    http://www.beansoftware.com/ASP.NET-Tutorials/Send-E-Mail.aspx

    http://www.sitepoint.com/article/sending-email-asp/

    http://www.asp101.com/samples/

    http://www.eukhost.com/forums/f32/send-email-asp-net-2302/

     

    Monday, November 10, 2008 5:33 AM
  • User507956310 posted

     Hi Gregale.net,

     thanks, but I know how to do the email sender I just  wonder where to put it ?? i.e. where to call my mailsender sub.

    Monday, November 10, 2008 6:49 AM