Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5958465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:32:48+00:00 2026-05-22T18:32:48+00:00

I am using a scheduler that will send out reminders through a library called

  • 0

I am using a scheduler that will send out reminders through a library called actionMailer. I however need the httpcontext to work as well actionMailer uses mvc.

So I came up with this:

// global aspx.

protected void Application_Start()
{
    // Hook our DI stuff when application starts
    IKernel kernel = SetupDependencyInjection();

    // get the reminder service
    IScheduledRemindersService scheduledRemindersService = kernel.Get<IScheduledRemindersService>();
    RemindersController.iScheduledReminedrService = scheduledRemindersService;
    RemindersController.StartScheduler();
}

// Reminder Controller

private static HttpContext httpContext;
public static void StartScheduler()
{
    // needed for action mailer
    httpContext = System.Web.HttpContext.Current;
    iScheduledReminedrService.StartAppointmentRemindersSchedule();
}

// Scheduler Service

public void StartAppointmentRemindersSchedule()
{
    // get a scheduler and start it.
    IScheduler scheduler = GetScheduler();
    scheduler.Start();

    // setup a job
    JobDetail jobDetail = SetupJob("AppointmentRemindersJob", typeof(AppointmentRemindersJob));

    //setup a trigger
    SimpleTrigger trigger = SetupSimpleTrigger("AppointmentRemindersTrigger");

    // schedule the job
    scheduler.ScheduleJob(jobDetail, trigger);
}

//Appointment Job

public void Execute(JobExecutionContext context)
{
    // code above to get CalendarAppointments
    RemindersController.CalendarAppointmentsReminders(calendarAppointments);
}

//Reminder Controller

[NonAction]
public static void CalendarAppointmentsReminders(List<CalendarAppointment> appointments)
{
    // set it to have a http context so we can send out emails through mvc mailer.
    System.Web.HttpContext.Current = httpContext;

    List<CalendarAppointmentReminderVM> vm = Mapper.Map<List<CalendarAppointment>, List<CalendarAppointmentReminderVM>>(appointments);

    foreach (var v in vm)
    {
        new EmailController().SendCalendarAppointmentNotifiation(v).DeliverAsync();
    }
}

// email controller

public EmailResult SendCalendarAppointmentNotifiation(CalendarAppointmentReminderVM vm)
{
    To.Add(vm.To);
    Subject = String.Format("Hi");
    return Email("SendCalendarAppointmentEmail", vm);
}

Works perfectly the first time I start up the application and run it. After that it crashes on the 2nd time around

System.NullReferenceException was
unhandled by user code
Message=Object reference not set to an
instance of an object.
Source=WebDev.WebHost40 StackTrace:
at Microsoft.VisualStudio.WebHost.Connection.get_RemoteIP()
at Microsoft.VisualStudio.WebHost.Connection.get_RemoteIP()
at Microsoft.VisualStudio.WebHost.Request.GetRemoteAddress()
at System.Web.HttpRequest.get_IsLocal()
at System.Web.HttpRequestWrapper.get_IsLocal()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext
pageContext, TextWriter writer,
WebPageRenderingBase startPage)
at System.Web.Mvc.RazorView.RenderView(ViewContext
viewContext, TextWriter writer, Object
instance)
at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext
viewContext, TextWriter writer)
at ActionMailer.Net.EmailResult.RenderViewAsString(ControllerContext
context, IView view)
at ActionMailer.Net.EmailResult.AddMessageViews(ControllerContext
context)
at ActionMailer.Net.EmailResult.ExecuteResult(ControllerContext
context)
at ActionMailer.Net.MailerBase.Email(String
viewName, Object model, String
masterName)
at EmailController.SendCalendarAppointmentNotifiation(CalendarAppointmentReminderVM
vm) in EmailController.cs:line 80
at RemindersController.CalendarAppointmentsReminders(List`1
appointments) in
RemindersController.cs:line 61
at AppointmentRemindersJob.Execute(JobExecutionContext
context) in
AppointmentRemindersJob.cs:line 40
at Quartz.Core.JobRunShell.Run()
InnerException:

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:32:49+00:00Added an answer on May 22, 2026 at 6:32 pm

    The HttpContext is not going to be reliably available out side of an actual http request made into IIS. Even if you set it to a static field. You could maybe try mocking a local request made to the site to kick off the email. I don’t know anything about ActionMailer, but perhaps their is a way to use their framework outside of the controller?

    To mock a request you’ll need to know the URL of the action you are targeting first, something like this should be a setting configured by the developer, or by the site automatically if possible.

            var client = new System.Net.WebClient();
            client.DownloadString("http://localhost/Controller/Action");
    

    This is not a recommended approach as their may be issues with permissions opening sockets and such. By far the best way to send an email is using framework that already exists such as System.Net.Mail.SmtpClient

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a program that will send GPS coordinates using telnet.
I need to execute a http web request from Plesk's Task Scheduler (using shared
Hey, I'm using Rails 2.3.5 and using rufus scheduler to send periodic emails. This
We receive vendor confirmation of file feeds that we send out. Some of our
Using Classic ASP (stop tutting), I need to build an application that transfers high
I need to schedule a task that will run everyday on 7:00 p.m. in
Before anyone flips out on me about singletons, I will say that in this
I need to write a tool that will run a recurring task on a
I need to install on one of my Windows PC's some software that will
I'm evaluating Rx for a trading platform project that will need to process thousands

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.