Mail Errors to Multiple Recipients

782 views
Skip to first unread message

ericday

unread,
Aug 12, 2006, 7:48:40 PM8/12/06
to ELMAH
Can ELMAH be configured to send the error mail to more than one
recipient?

I have tried different things like adding more than one email separated
with a semi-colon and also replicating the <errorMail> tag in the
web.config. So far nothing has worked. I might be overlooking
something obvious.

Eric

unread,
Aug 12, 2006, 8:13:48 PM8/12/06
to ELMAH
Wich version are you using? .NET 1.1 or 2.0?
If you are using the .NET 1.1 version (System.Web.Mail), the semicolon
separated list, should work.

ericday

unread,
Aug 13, 2006, 3:17:12 PM8/13/06
to ELMAH
I am using the 2.0 version.

Atif Aziz

unread,
Aug 13, 2006, 3:53:57 PM8/13/06
to el...@googlegroups.com, Andrew Cain
The original ELMAH for ASP.NET 1.1 allows for multiple recipients. The
ELMAH2 download was a community contribution from Andrew Cain, who made
the most extensive changes to the ErrorMailModule. Looking at the code,
it seems his version does not handle multiple recipients. I've CC'd
Andrew on the response, so if he's listening, may be he'll pitch in.
Meanwhile, even though the original ELMAH is compiled using 1.1, it is
binary compatible with 2.0 and you can drop it in and use it right away.

Atif Aziz

unread,
Aug 13, 2006, 3:57:50 PM8/13/06
to el...@googlegroups.com
Of course, the code change is rather trivial too if you want to go ahead
with it. In ErrorMailModule.cs (of ELMAH2 sources), change the following
line:

mail.To.Add(new MailAddress(recipient));

To instead read:

foreach (string address in recipient.Split(";"))
mail.To.Add(new MailAddress(address));

Hope this helps.

- Atif

ericday

unread,
Aug 13, 2006, 5:19:51 PM8/13/06
to ELMAH
It looks like you found the culprit. Thanks for pointing me in the
right direction.

Andrew Cain

unread,
Aug 14, 2006, 2:00:24 AM8/14/06
to Atif Aziz, el...@googlegroups.com
Hey guys,  I will have a look at this when I get a chance.  In the mean time you can work around with a distribution list.  Have you tried using a comma to separate out the addresses?  I don't remember what the code is doing off of the top of my head.

Thanks,
:D

ericday

unread,
Aug 14, 2006, 11:48:04 AM8/14/06
to ELMAH
I almost resorted to an Outlook rule but it looks like Atif found the
problem. The code in the 2.0 version wasn't splitting and looping
through the recipient list.

For future reference I had to use this code.
foreach (string address in recipient.Split(new Char[] {';'}))
mail.To.Add(new MailAddress(address));

Minor change from what was suggested. Split wanted a character array
instead of a string.

I should also note that if you use a multiple recipient list you need
to use the from attribute on the <errorMail> tag. If the from isn't
there it uses the to attribute as the default. However, trying to use
something like ma...@domain.com;ma...@domain.com as the sender address
will cause an error. A simple code fix would be to check for multiple
recipients and if more than one set the sender to the first one. This
is of course if the from attribute is missing. I am going to just add
the from attribute but I thought I would pass that potential situation
along.

Atif Aziz

unread,
Aug 14, 2006, 12:24:36 PM8/14/06
to el...@googlegroups.com, Andrew Cain
> Split wanted a character array instead of a string.

Ah yes well that's the problem for not having code IntelliSense in your
mail editor. :-P Since String.Split supports variable-arguments syntax
sugar, you should be able to get away with just changing the double
quotes to single quotes, as in:

foreach (string address in recipient.Split(';'))
mail.To.Add(new MailAddress(address));

Good catch about the "from" attribute.

- Atif

-----Original Message-----
From: el...@googlegroups.com [mailto:el...@googlegroups.com] On Behalf
Of ericday
Sent: Monday, August 14, 2006 5:48 PM
To: ELMAH
Subject: Re: Mail Errors to Multiple Recipients

ericday

unread,
Aug 14, 2006, 11:23:17 PM8/14/06
to ELMAH
I tried the single quotes in VS2005 and it didn't complain. I didn't
build and test though. I am sure it would work. I use VB so I just
went by the examples on MSDN. I didn't know about the single quotes.

Thanks for the tip.

Atif Aziz

unread,
Aug 15, 2006, 2:41:46 AM8/15/06
to el...@googlegroups.com
In VB, you'd have to write:

String.Split(";"C)

Since VB uses single quotes for comments, a character uses double quotes
but is immediately followed by the character C to denote that it's a
single character (of type System.Char) instead of an entire string
(System.String). May be you're not compiling in Option Strict mode so VB
is making an implicit conversion. It should pass however at runtime.

-----Original Message-----
From: el...@googlegroups.com [mailto:el...@googlegroups.com] On Behalf
Of ericday
Sent: Tuesday, August 15, 2006 5:23 AM
To: ELMAH
Subject: Re: Mail Errors to Multiple Recipients

Reply all
Reply to author
Forward
0 new messages