这是msdn中的一个例子,但我用vs.net 2003编译时说找不到 System.Web.Mail,请问这是为什么呀?我在系统是XP.我是新建的一个windows applicaton,然后把代码复制到form1.cs 中编译的.using System;
using System.Web.Mail;
 
namespace SendMail
{
   class usage
   {
      public void DisplayUsage()
      {
         Console.WriteLine("Usage SendMail.exe <to> <from> <subject> <body>");
         Console.WriteLine("<to> the addresses of the email recipients");
         Console.WriteLine("<from> your email address");
         Console.WriteLine("<subject> subject of your email");
         Console.WriteLine("<body> the text of the email");
         Console.WriteLine("Example:");
         Console.WriteLine("SendMail.exe [email protected];[email protected] [email protected] Hi hello");
      }
   }
    class Start
   {
      // The main entry point for the application.
      [STAThread]
      static void Main(string[] args)
      {
         try
         {
            try
            {
               MailMessage Message = new MailMessage();
               Message.To = args[0];
               Message.From = args[1];
               Message.Subject = args[2];
               Message.Body = args[3];               try
               {
                  SmtpMail.SmtpServer = "your mail server name goes here";
                  SmtpMail.Send(Message);
               }
               catch(System.Web.HttpException ehttp)
               {
                  Console.WriteLine("{0}", ehttp.Message);
                  Console.WriteLine("Here is the full error message output");
                  Console.Write("{0}", ehttp.ToString());
               }
            }
            catch(IndexOutOfRangeException)
            {
               usage use = new usage();
               use.DisplayUsage();
            }
         }
         catch(System.Exception e)
         {
            Console.WriteLine("Unknown Exception occurred {0}", e.Message);
            Console.WriteLine("Here is the Full Message output");
            Console.WriteLine("{0}", e.ToString());
         }
      }
   }
}

解决方案 »

  1.   

    项目-->引用-->添加引用-->.NET-->(选择)System.Web.dll
      

  2.   

    楼上正解
    如果没有System.Web.dll,那么你就要重装.net framework了。
      

  3.   

    要引用System.Web.Dll还有如果你机器不是SMTP服务器
    上面那段代码是发不出邮件的。你搜索一下CSDN发邮件的旧贴。
      

  4.   

    需添加dll,
    http://www.systemwebmail.com/default.aspx
      

  5.   

    我看到这么一篇:使用System.Web.Mail名称空间连接需要验证的SMTP服务器 只需对增加相应标识即可:
    // 使用SmtpMail对象发送邮件MailMessage mailObj = new MailMessage();   mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //设置需要验证
       mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", username); //用户名
       mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",  password); //密码我觉得username,password 不会是你登录邮箱时的username&password吧?因为后面还有:
       // 设置邮件的发送及接收地址
       mailObj.From = from;
       mailObj.To = sendto;
    而且发邮件也用不着username&password 吧?