Thumb

Part-2 : Send Email using Hangfire Scheduler ASP.NET MVC |Background job| C# |Auto mail send

11/5/2019 7:21:12 AM

Download Project  (Full Project)

Step-1

In this part i will show how to Send Email using Hangfire Scheduler ASP.NET MVC. First Open visual studio then opens our existing project where we are working. Now write some code into home controller index view. Mainly this index method run the Hangfire or calls the Hangfire method then the functionality is active. Given bellow the code:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)  
{  
    loggerFactory.AddConsole(Configuration.GetSection("Logging"));  
    loggerFactory.AddDebug();  
  
    app.UseHangfireDashboard();  
    app.UseHangfireServer();  
      
    app.UseDeveloperExceptionPage();  
    app.UseBrowserLink();  
      
    app.UseStaticFiles();  
    app.UseMvc(routes =>  
    {  
        routes.MapRoute(  
            name: "default",  
            template: "{controller=Home}/{action=Index}/{id?}");  
    });  
}  

Step-2

Open Startup.cs class and locate a ConfigureServices method to register Hangfire as a service. Given bellow the code:

public void ConfigureServices(IServiceCollection services)  
	{  
	    services.AddHangfire(x => x.UseSqlServerStorage(Configuration.GetConnectionString("DefaultConnection")));  
	    services.AddMvc();  
	}  

Step-3

View is represent the some menu to go to the link. And we can see the scheduling view. Now build and run the project.  

About Teacher

Image

Reza Karim

Software Engineer

More about him