//在reference中添加CDO  for  Windows  2000  
 
using  CDO;  
 
   
 
public  void  SendEmail()  
{  
 
 
     try  
     {  
       Configuration  conf=new  ConfigurationClass();  
       
       conf.Fields[CdoConfiguration.cdoSendUsingMethod].Value=CdoSendUsing.cdoSendUsingPort;  
       conf.Fields[CdoConfiguration.cdoSMTPServer].Value="smtp.netease.com";  
       conf.Fields[CdoConfiguration.cdoSMTPServerPort].Value=25;  
       conf.Fields[CdoConfiguration.cdoSMTPAccountName].Value="hydnoahark";  
       conf.Fields[CdoConfiguration.cdoSendUserReplyEmailAddress].Value="\"hydnoahark\"  <[email protected]>";  
       conf.Fields[CdoConfiguration.cdoSendEmailAddress].Value="\"hydnoahark\"  <[email protected]>";  
       conf.Fields[CdoConfiguration.cdoSMTPAuthenticate].Value=CdoProtocolsAuthentication.cdoBasic;  
       conf.Fields[CdoConfiguration.cdoSendUserName].Value="hydnoahark";  
       conf.Fields[CdoConfiguration.cdoSendPassword].Value="xxx";  
         
       conf.Fields.Update();  
 
       MessageClass  msg=new  MessageClass();  
       msg.Configuration=conf;  
 
       msg.To="[email protected]";  
       msg.Subject="Hello";  
       msg.TextBody="It's  test";  
       msg.From="[email protected]";  
 
       msg.Send();        
     }  
     catch(System.Runtime.InteropServices.COMException  e)  
     {  
       MessageBox.Show(e.ToString());  
     }  
 
     return;  
}  
 
 

解决方案 »

  1.   

    to sumanden
    我是用本地的STMP服务器发的呀!
      

  2.   

    System.Web.Mail.SmtpMail.SmtpServer = "localhost";
      

  3.   

    to acewang(**^o^**) 按您方法,出现如下错误:The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available
      

  4.   

    http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=5138
      

  5.   

    http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=5138
    打不开
      

  6.   

    using System;
    using System.Web.Mail;
    using CDO;
    namespace Greystar.Base.Office
    {
    /// <summary>
    /// Email 的摘要说明。
    /// </summary>
    public class Email
    {
    public Email()
    {
    //
    // TODO: 在此处添加构造函数逻辑
    //
    } #region  SendEmailValidate (string Emailfrom,string Emailto,string subject,string mailbody)
    /// <summary>
    /// 要求有帐号
    /// </summary>
    /// <param name="Emailfrom"></param>
    /// <param name="Emailto"></param>
    /// <param name="subject"></param>
    /// <param name="mailbody"></param>
    public void SendEmailValidate (string Emailfrom,string Emailto,string subject,string mailbody)
    {
    string ErrString="";
    try
    {
    Configuration conf=new Configuration();
    //以下部分设置参数(服务器,端号,用户名,密码,发送邮件帐号,回复邮箱帐号)
    conf.Fields[CdoConfiguration.cdoSendUsingMethod].Value=CdoSendUsing.cdoSendUsingPort;
    conf.Fields[CdoConfiguration.cdoSMTPServer].Value="server-mail";
    conf.Fields[CdoConfiguration.cdoSMTPServerPort].Value=25;
    conf.Fields[CdoConfiguration.cdoSMTPAccountName].Value="greystar";
    conf.Fields[CdoConfiguration.cdoSendUserReplyEmailAddress].Value="\"greystar\" <[email protected]>";
    conf.Fields[CdoConfiguration.cdoSendEmailAddress].Value="\"greystar\" <[email protected]>";
    conf.Fields[CdoConfiguration.cdoSMTPAuthenticate].Value=CdoProtocolsAuthentication.cdoBasic;
    conf.Fields[CdoConfiguration.cdoSendUserName].Value="greystar";
    conf.Fields[CdoConfiguration.cdoSendPassword].Value="liaoliao";
        
    conf.Fields.Update();
    MessageClass msg=new MessageClass(); msg.Configuration=conf;

    msg.To=Emailto;
    msg.Subject= subject;
    msg.HTMLBody=mailbody;
    msg.From=Emailfrom; msg.Send();  
    ErrString="确认成功";
    }
    catch(System.Runtime.InteropServices.COMException Ee)
    {  
    ErrString=Ee.Message;
    throw new Exception(ErrString);
    }
    }
    #endregion  #region SendMail(string MailFrom,string MailTo,string MailSubject,string MailBody,string MailServer  )
    /// <summary>
    /// 匿名访问
    /// </summary>
    /// <param name="MailFrom"></param>
    /// <param name="MailTo"></param>
    /// <param name="MailSubject"></param>
    /// <param name="MailBody"></param>
    /// <param name="MailServer"></param>
    public void SendMail(string MailFrom,string MailTo,string MailSubject,string MailBody,string MailServer  ) { MailMessage Msg = new MailMessage(); Msg.To      = MailTo; Msg.Subject = MailSubject; Msg.Body    = MailBody; Msg.From =MailFrom; SmtpMail.SmtpServer=MailServer; SmtpMail.Send(Msg); return; }
    #endregion
    }
    }
      

  7.   

    打开你的IIS manager,选择SMTP的属性,选择access,选择里面的最后一个按钮 Relay, 选择all except the list below,然后一路ok,一两分钟后,邮件就开始工作了。
      

  8.   

    http://expert.csdn.net/Expert/topic/2177/2177134.xml?temp=.175564
      

  9.   

    to  dawave() 
    ------------------------------------
    我是用Win2000 OS 我也觉得不是代码的问题,因为我用CDO或其它下载的组件结果都有一样--
    邮件都写好了,就是在C:\Inetpub\mailroot\Queue下待发,用你那种方法好像还是不行!
      

  10.   

    如果发邮件没有报错,但邮件停在队列里,八成就是这个问题,你再仔细查查。试着reboot你的机器。
      

  11.   

    设置SmtpMail.SmtpServer = 本地smtp地址;要确认这个smtp地址没问题!
    然后SmtpMail.Send(mail);