如何在asp.net中创建邮件调度程序应用程序



我的问题是,我必须每天在特定时间发送邮件,在asp.net中有任何方法可以做到这一点吗?给我适当的建议。注意:我不想运行windows应用程序或windows调度程序。

我在global.asax中使用的

代码

 private static CacheItemRemovedCallback OnCacheRemove = null;
    void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
        AddTask("Remoder", 5);
    }
    void Application_End(object sender, EventArgs e) 
    {
        //  Code that runs on application shutdown
    }
    void Application_Error(object sender, EventArgs e) 
    { 
        // Code that runs when an unhandled error occurs
    }
    void Session_Start(object sender, EventArgs e) 
    {
        // Code that runs when a new session is started
    }
    void Session_End(object sender, EventArgs e) 
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.
    }
    private void AddTask(string name, int seconds)
    {
        OnCacheRemove = new CacheItemRemovedCallback(CacheItemRemoved);
        HttpRuntime.Cache.Insert(name, seconds, null,
            DateTime.Now.AddSeconds(seconds), Cache.NoSlidingExpiration,
            CacheItemPriority.NotRemovable, OnCacheRemove);
    }
    public void CacheItemRemoved(string k, object v, CacheItemRemovedReason r)
    {
        // do stuff here if it matches our taskname, like WebRequest
        // re-add our task so it recurs
        AddTask(k, Convert.ToInt32(v));
    }
    public void Remoder()
    {
        HttpContext.Current.Response.Write("Hello Start");
    }

看看http://quartznet.sourceforge.net/

我认为Jeff自己的这个技巧是你需要的:https://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/

我试过了…将应用程序转为全局。Asax放入虚拟调度器中。这是我的选择,因为我的服务器管理部门拒绝(因为他们不理解)在windows或数据库作业中这样做。

如果我有我的选择,我将使用数据库"作业",因为sql-server可以直接发送邮件。不确定你在使用什么数据库,但如果你有必要的访问权限,我建议寻找这样的解决方案,而不是试图愚弄你的asp.net应用程序。

最新更新