c# - 为什么 MailDefinition 类需要 System.Web.UI.Control?

标签 c# asp.net mailmessage

通过调用 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/

相关文章:

c# - 通过 REST 进行 DDD 更新

powershell - 发送-替换HTML电子邮件

c# - 如何从我的 C# 应用程序发送电子邮件?

C# 从流中压缩和压缩 csv

c# - ADO.NET 实体对象生成器

c# - 如何制作整数 ID 生成器?

c# - PictureBox 大小不正确

c# - 在 C# 中使用 shutdown.exe 关闭另一个系统?

c# - 使用 JavaScript 查找具有多个 ASP UserControl 的 ID

asp.net - Docker 错误 : failed to register layer: Error processing tar file(exit status 1): "...msader15.dll.mui: no such file or directory"