title: Sending ELMAH error email manually
body: <p>Note that this is not related to getting emails set up in the traditional sense of elmah, I have already successfully done so.</p>
  
  <p>I am attempting to utilize a github project (<a href="https://github.com/dylanbeattie/ElmahASP" rel="nofollow">https://github.com/dylanbeattie/ElmahASP</a>) that was created to send "realish" errors to elmah from classic asp pages.</p>
  
  <p>I have this implemented so that in the project on .net pages, errors are logged/emails sent. On classic asp pages, errors are logged, but no email is sent (here lies my issue)</p>
  
  <p>The errors are logged in classic asp via a custom handler (provided by the github project):</p>
  
  <pre><code>    public void ProcessRequest(HttpContext context) {
          try {
              var jsonData = new StreamReader(context.Request.InputStream).ReadToEnd();
              var aspError = JsonConvert.DeserializeObject&lt;RemoteError&gt;(jsonData);
              var elmahError = aspError.ToElmahError();
              //TODO: might be worth putting some code in here that will determine the username based on the cookie collection in the deserialized error object.
              ErrorLog.GetDefault(HttpContext.Current).Log(elmahError);
              context.Response.Write("Error logged OK!");
          } catch (Exception ex) {
              ErrorSignal.FromCurrentContext().Raise(ex);
          }
          context.Response.Write("THis is a response!");
      }
  </code></pre>
  
  <p>It appears that doing a <code>ErrorLog.Log</code> does in fact log the error, but bypasses the event that would need to be thrown that would cause an error email to be sent out.  The elmah class that handles sending out emails has several non public methods for sending out mail which I wanted to utilize, however the following is not working due to me not understanding... something.</p>
  
  <p>I have attempted to write an extension of the mail module, have successfully registered it (as I've confirmed aspx pages are still sending out emails, but am still having problems with classic asp error mails).  Here is my class:</p>
  
  <pre><code>public class ErrorMailModule : Elmah.ErrorMailModule
  {
      public void SendErrorMail(Elmah.Error error)
      {
          base.ReportError(error);
      }
  }
  </code></pre>
  
  <p>I then change the handler from above to:</p>
  
  <pre><code>    public void ProcessRequest(HttpContext context) {
          try {
              var jsonData = new StreamReader(context.Request.InputStream).ReadToEnd();
              var aspError = JsonConvert.DeserializeObject&lt;RemoteError&gt;(jsonData);
              var elmahError = aspError.ToElmahError();
              //TODO: might be worth putting some code in here that will determine the username based on the cookie collection in the deserialized error object.
              ErrorLog.GetDefault(HttpContext.Current).Log(elmahError);
  
              ErrorMailModule mail = new ErrorMailModule;
              mail.SendErrorMail(elmahError);
  
              context.Response.Write("Error logged OK!");
          } catch (Exception ex) {
              ErrorSignal.FromCurrentContext().Raise(ex);
          }
          context.Response.Write("THis is a response!");
      }
  </code></pre>
  
  <p>This however doesn't work, I'm quite sure it's due to me newing up a error mail module, rather than by utilizing the one that I'm (assuming) is registered at init - but I'm unsure how to do that.</p>
  
  <p>I feel like having a custom event registered and monitored for (then raised in the handler) would be one way to go... but I am unsure on how to proceed as I've never worked with events.</p>
  
  <p>How would I go about implementing this?  Would events be the way to go or is there another path I could take?</p>