MailDefinition ASP.Net应用程序之外 [英] MailDefinition Outside of ASP.Net Application

查看:114
本文介绍了MailDefinition ASP.Net应用程序之外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期待写一个C#控制台应用程序,将在运行发送电子邮件的过程。我有电子邮件走出去简单地做一些这样的:

I'm looking to write a C# console app that will, in the process of running send out emails. I have the emails going out simply by doing something like:

     MailMessage message = new MailMessage("foo@foo.com", "bar@bar.com", "Test message", "Test message content");
     message.IsBodyHtml = true;
     message.Body = "<a href=\"http://www.daringfireball.net\">DaringFireball.net</a>";
     SmtpClient client = new SmtpClient("localhost"); // Your host here

     try
     {
        client.Send(message);
     }
     catch (Exception e)
     {
        Console.WriteLine("There was an error trying to send the message: " + e.ToString());
     }



我试图找到一种方法与MailDefinition做到这一点,因为这些邮件可能更长,但在这样做,我遇到了一个小问题的过程。该CreateMailMessage方法需要我没有,因为我不是一个ASP.Net应用System.Web.UI.Control。

I was trying to find a way to do this with MailDefinition because these emails might be longer, but in the process of doing that I ran into a little problem. The CreateMailMessage method requires a System.Web.UI.Control which I don't have because I'm not an ASP.Net Application.

有没有人碰到这个问题?或者发现这样做的更好的办法?

Has anyone run into this problem? Or found a better way of doing this?

感谢

推荐答案

确保你使用正确的.Net框架4,而不是.Net框架4客户为目标的框架。
添加的System.Web到项目的引用

Ensure you've used correct .Net Framework 4 and not .Net Framework 4 client as the target framework. Add System.Web to the references of your project.

然后创建作为MAILMESSAGE:
MAILMESSAGE msgHtml = message.CreateMailMessage(收件人,更换,新System.Web.UI.Control());

Then create the Mailmessage as: MailMessage msgHtml = message.CreateMailMessage(recipients, replacements, new System.Web.UI.Control());

这篇关于MailDefinition ASP.Net应用程序之外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆