Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MailDefinition's CreateMailMessage owner from ASP.Net MVC Controller

What do I send as the owner for a MailDefinition.CreateMailMessage() sent through an ASP.Net MVC Controller?

//   owner:
//     The System.Web.UI.Control that owns this System.Web.UI.WebControls.MailDefinition.
public MailMessage CreateMailMessage(string recipients, IDictionary replacements, Control owner);

Edit: sending a new System.Web.UI.Control() seems to work ok. Is there a different/standard solution?


1 Answers

I had the same problem as Adam after adapting the code described in system.web.ui.webcontrols.maildefinition

The solution is to replace "this" by "new System.Web.UI.Control()"

For example, in the C# Microsoft example above, instead of:

fileMsg = md.CreateMailMessage(sourceTo.Text, replacements, this);

In an MVC Controller you would write:

fileMsg = mailDefinition.CreateMailMessage("[email protected]", replacements, new System.Web.UI.Control());
like image 189
Thomas Amar Avatar answered Feb 27 '26 02:02

Thomas Amar