asp.net net.mail - 路由所有邮件到不同的电子邮件地址,在调试模式路由、电子邮件地址、不同、邮件

2023-09-03 21:24:15 作者:忘乎所以。

反正是有让所有邮件到一个不同的地址时, System.Web.HttpContext.Current.IsDebuggingEnabled 是真的吗?或者我需要我用到处发送电子邮件一类新的?

Is there anyway to have all emails go to a different address when System.Web.HttpContext.Current.IsDebuggingEnabled is true? Or do I need a new class which I use to send email everywhere?

推荐答案

我们使用类似的解决了MailProxy方法,通过tvanfosson详细说明。但是我们有,我觉得是值得一提的有一些区别。第一个是我们根本扩展SmtpClient类,并在开发或测试环境时覆盖发送方法。我们用一个配置文件,以确定环境。然后,我们使用这个类任何时候,我们需要发送电子邮件。这个类将决定谁是当前登录到应用程序和重定向产生的对他们的所有电子邮件,具有故障转移到收件人的标准列表,如果登录用户不提供任何原因。这可以帮助,如果您有谁正在测试或开发,因为他们只会让他们产生的电子邮件数人。我们也prePEND原始收件人的信息发送到邮件正文。这种测试工作流类型的消息时,以确保它们要正确个人再次是有用的。最后,我觉得是非常有用的一个[DEV]或[QA]标签添加到邮件的主题,所以我可以设置一个规则在我的邮件客户端来处理所有测试的消息。

We use a similar solution to the MailProxy method detailed by tvanfosson. However we have a few differences that I feel are worth mentioning. The first is that we simply extend the SmtpClient class and override the Send methods when in a development or testing environment. We use a config file to determine the environment. We then use this class anytime we need to send out emails. This class will determine who is currently logged into the application and redirect all emails generated to them, with a failover to a standard list of recipients if the logged in user is not available for whatever reason. This helps if you have several people who are testing or developing as they will only get the emails they generated. We also prepend the original recipients of the message to the body of the message. This again is useful when testing workflow type messages to ensure that they are going to the correct individuals. Finally, I find it's useful to add a [DEV] or [QA] tag to the subject of the message so I can set up a rule in my mail client to handle all testing messages.