我正在使用 errorMail 功能 埃尔玛 当 ASP.NET 遇到错误时发送电子邮件。它允许您配置 SMTP 设置以及对发件人、收件人和主题进行硬编码。

我的问题是: 我可以使用动态主题吗?具体来说,我想使用 Exception.Message 属性作为我的主题,以便我可以仅从电子邮件的主题行判断错误的内容。

没有文档,从源代码的快速扫描来看,如果不修改代码似乎是不可能的,但我想无论如何我都会问这个问题。

相关源码:

有帮助吗?

解决方案

哎哟!答案已开启 ErrorMailModule.cs 的第 454 行:

string subjectFormat = Mask.EmptyString(this.MailSubjectFormat, "Error ({1}): {0}");
mail.Subject = string.Format(subjectFormat, error.Message, error.Type)
                .Replace('\r', ' ')
                .Replace('\n', ' ');

您可以使用 {0} 作为消息,使用 {1} 作为类型。

其他提示

我已通过以下方式更改了 web.config 文件中的电子邮件主题:

<errorMail from="..." subject="Some subject: {0}">

其中 {0} 是异常消息。

您可以查看这篇文章了解更多详细信息 http://weblogs.asp.net/jeffwids/format-the-email-subject-in-the-elmah-error-logging-module

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top