Elmah
email notifications
error monitoring
ASP.NET
logging

Send email from Elmah?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

ELMAH can send email notifications when an ASP.NET application logs an unhandled error. The feature is built around the mail module and standard ASP.NET mail settings, so the real job is configuring ELMAH and SMTP correctly. Once that is in place, ELMAH will email a formatted error report whenever a matching exception is captured.

What ELMAH Actually Sends

Classic ELMAH for ASP.NET can log errors to different backends and optionally notify you by email. The mail feature is useful when you want immediate visibility into production failures without constantly checking the error log UI.

The usual flow is:

  1. ELMAH captures an exception
  2. the mail module formats an error message
  3. ASP.NET SMTP settings are used to send the email

That means a working SMTP setup is just as important as the ELMAH configuration itself.

Basic web.config Setup

A typical configuration includes the ELMAH error mail module and an SMTP section.

xml
1<configuration>
2  <configSections>
3    <sectionGroup name="elmah">
4      <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
5    </sectionGroup>
6  </configSections>
7
8  <elmah>
9    <errorMail
10      from="[email protected]"
11      to="[email protected]"
12      subject="ELMAH error from MyApp"
13      async="true" />
14  </elmah>
15
16  <system.net>
17    <mailSettings>
18      <smtp from="[email protected]">
19        <network host="smtp.example.com"
20                 port="587"
21                 userName="smtp-user"
22                 password="smtp-password"
23                 enableSsl="true" />
24      </smtp>
25    </mailSettings>
26  </system.net>
27</configuration>

This is the core idea: ELMAH defines who should receive the notification, and system.net defines how to send it.

Make Sure the Module Is Active

In classic ASP.NET applications, ELMAH must be registered in the app's module pipeline. If the mail configuration exists but the module is not active, no emails will be sent.

The exact registration style depends on the app and IIS mode, but the important point is operational: verify that ELMAH is actually capturing errors before debugging the mail path.

A good first test is to trigger a known exception and confirm that it appears in the ELMAH error log UI or storage backend.

Filtering Which Errors Send Mail

Sending an email for every exception can become noisy fast. Many teams filter common or low-value errors so inboxes stay useful.

Examples you may want to suppress:

  • 404 errors for missing assets
  • crawler noise
  • known handled exceptions that are already monitored elsewhere

The exact filter setup depends on the ELMAH version and hosting model, but the operational rule is the same: treat email as a signal channel, not a dumping ground.

SMTP Problems Are Often the Real Issue

If ELMAH logs the exception but no email arrives, the failure is often outside ELMAH itself.

Common causes:

  • wrong SMTP host or port
  • invalid credentials
  • SSL or TLS mismatch
  • firewall blocks
  • sender address rejected by the mail server

That is why it is useful to validate the SMTP settings independently. If the application cannot send ordinary mail, ELMAH mail will fail too.

A Practical Testing Approach

Use a staging environment or a deliberate test exception.

csharp
1protected void Page_Load(object sender, EventArgs e)
2{
3    throw new InvalidOperationException("ELMAH mail test");
4}

If the exception is logged but no email arrives, investigate the SMTP path. If nothing is logged at all, fix ELMAH pipeline registration first.

Common Pitfalls

The biggest mistake is assuming ELMAH mail is broken when the real issue is invalid SMTP configuration.

Another mistake is enabling email for every logged exception and then creating alert fatigue.

A third issue is testing mail before confirming that ELMAH is actually recording the error in the first place.

Summary

  • ELMAH can send error emails through its mail module plus standard ASP.NET SMTP settings
  • Configure both the ELMAH errorMail section and the system.net SMTP section
  • Verify that ELMAH is logging exceptions before troubleshooting email delivery
  • Filter low-value errors so notification email remains useful
  • Most mail failures come from SMTP configuration, credentials, or transport issues rather than ELMAH itself

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.