通过调用 MailDefinition 类的“CreateMailMessage”方法创建 MailMessage 对象时,第三个参数是 System.Web.UI.Control 类型的对象。
MailDefinition mail = new MailDefinition();
ListDictionary replacements = new ListDictionary();
replacements.Add("<%myname%>", "John");
mail.BodyFileName = "~/App_Data/Emails/SomeEmail.txt";
mail.From = "me@example.com";
mail.Subject = "Hello";
MailMessage message = mail.CreateMailMessage("example@example.com,", replacements, );
这是为什么?
如果我没有那种类型的对象,我应该传递什么?只是一个新的控制对象?
Control control = new Control();
更新
我强烈推荐使用 Razor构建电子邮件模板。它的语法很好,运行良好,并且没有任何奇怪的依赖关系!
最佳答案
通常您只需将 this
作为控件传递即可。
MailMessage message = mail.CreateMailMessage("example@example.com,", replacements, this);
至于为什么,here is what MSDN says:
The owner parameter indicates which control is the parent of the MailDefinition control. It determines which directory to search for the text file specified in the BodyFileName property.
关于c# - 为什么 MailDefinition 类需要 System.Web.UI.Control?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/744117/