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.   

    http://dotnet.aspx.cc/ShowDetail.aspx?id=E69A82C0-C002-4D2D-9787-5FEBBA47AC8Fhttp://blog.csdn.net/zhzuo/archive/2004/07/12/39459.aspx
      

  2.   

    你是想知道如何配置Win 2000 里的SMTP实现外发邮件吗???1.打开IIS
    2.右击SMTP服务中的"域",在弹出的菜单中选择"新建"-"域"
    3.在"新建SMTP域向导"中选择"远程"
    4.在"名称"中输入你要外发的邮件的域名,一般情况下[email protected]的邮件域名就输入"*.com",如果是[email protected]就输入"*.net",以此类推.
    5.在新加入的域上右击,选择"属性"
    6.在"属性"窗口中选择"允许将传入邮件中继到此域","发送HELO,而不是EHLO","使用DNS以发送到此域"
    7.确定
    此时,就完成了SMTP 外发邮件到.com域的配置工作.其它域以此类推即可.此时,用自己的代码实现发送邮件或用Foxmail,OE等邮件客户端都可以实现用该主机外发邮件的功能.
      

  3.   

    楼上几位贴的代码都是如何实现发送邮件的,应该都没问题.但是,在我的实际开发过程中,有许多客户的邮件系统都是Exchange Server,而其众多服务器中,有一台直接使用Win2000 的SMTP来进行邮件发送,但是,如果不通过我讲的配置方法去配置的话,有很多的邮件发送代码在未进行配置的主机上无法实现发送功能,尽管代码调试没有问题.因此,有时在代码测试的过程中,网络及软件的环境也很重要.
      

  4.   

    异常详细信息: System.Runtime.InteropServices.COMException: The transport failed to connect to the server. 怎么回事啊??
    我按上面说的配的
      

  5.   

    System.Web.Mail.MailMessage mMail;mMail=new MailMessage();
    mMail.Subject="Subject";
    mMail.From="[email protected]";
    mMail.To="[email protected]";
    mMail.Body="Mail body.";System.Web.Mail.SmtpMail.SmtpServer="localhost";
    System.Web.Mail.SmtpMail.Send(mMail);就用以上的代码就可以实现邮件发送,SmtpServer设置成已经配置了SMTP Service的主机名或是IP即可.
      

  6.   

    不好意思,还是报错,可能是我的网络问题。我是大家共享的一条ADSL,都是自动分配的IP地址,是不是因为这个才不能够发出电子邮件呢?