I'm using the errorMail functionality of Elmah to send an email when ASP.NET encounters an error. It allows you to configure the SMTP settings as well as hard-code a sender, recipient, and subject.
My question is: can I use a dynamic subject ? Specifically, I would like to use the Exception.Message property as my subject, so that I can tell what the error is about just from the subject line of the email.
There is no documentation, and from a quick scan of the source code it looks impossible without modifying the code, but I thought I would ask the question anyways.
Relevant source code:
Doh! Answer is on line 454 of ErrorMailModule.cs :
string subjectFormat = Mask.EmptyString(this.MailSubjectFormat, "Error ({1}): {0}");
mail.Subject = string.Format(subjectFormat, error.Message, error.Type)
.Replace('\r', ' ')
.Replace('\n', ' ');
I've changed the email subject from the web.config file in this way:
<errorMail from="..." subject="Some subject: {0}">
where {0} will be the exception message.
You can check this article for more details http://weblogs.asp.net/jeffwids/format-the-email-subject-in-the-elmah-error-logging-module
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.