我得程序是这样写的:
private void btnLogin_Click(object sender, System.EventArgs e)
 {SmtpMail.Send(txtEMail.Text,txtEMail.Text, "test", "this is a test");
 }
运行后系统提示:异常详细信息: System.Runtime.InteropServices.COMException: “SendUsing”配置值无效。
应该怎么改亚?

解决方案 »

  1.   

    The SmtpMail class can be used to send mails from your C# application. Mail is by default queued on the system, ensuring that the calling program does not block network traffic. The SmtpMail class is defined in the namespace System.Web.Util. You need to call using System.Web.Util before you use SmtpMail. This class has only one member function Send. Send sends a mail message. The Send method is overloaded. Either a MailMessage class or four arguments can be passed to the Send message. You can call the Send method in two manners:SmtpMail.Send(txtFrom.Text, txtTo.Text, txtSubject.Text, txtMessage.Text); Or, if you don't want to call System.Web.Util.System.Web.Util.Smptmail.Send( fromString, toString, SubjeOfTheMailString, MessageOfTheMailString ); You can call the Send method in two ways. 1. By passing MailMessage as a parameter, public static void Send(MailMessage); Here MailMessage is a class.            MailMessage mailMsg = new MailMessage();
                mailMsg .From = "[email protected]";
                mailMsg .To = "[email protected]";
                mailMsg .Cc = "[email protected]"";
                mailMsg .Bcc = "[email protected]";
                mailMsg .Subject = "SubjectOfTheMailString";
                mailMsg .Body = "BodyOfTheMailString";
                SmtpMail.Send(mailMsg );
     2. Direct method.public static void Send(string from , string to, string subject, string messageText); rameters Description: 
    from: Email address of sender 
    to: Email address of recipient 
    subject: Email subject line. 
    messageText: Body of Email message Example:SmtpMail.Send("[email protected]", "[email protected]", "Subject", "Message body"); 
      

  2.   

    不行压,还是这个错:
    [COMException (0x80040220): “SendUsing”配置值无效。
    ][TargetInvocationException: 调用的目标发生了异常。]
       System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) +0
       System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) +473
       System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args) +29
       System.Web.Mail.LateBoundAccessHelper.CallMethod(Type type, Object obj, String methodName, Object[] args)
       System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args)[HttpException (0x80004005): 未能访问“CDO.Message”对象。]
       System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args)
       System.Web.Mail.CdoSysHelper.Send(MailMessage message)
       System.Web.Mail.CdoSysHelper.Send(String from, String to, String subject, String messageText)
       System.Web.Mail.SmtpMail.Send(String from, String to, String subject, String messageText)
       app.WebForm1.btnLogin_Click(Object sender, EventArgs e) in i:\yan\asp\app\webform1.aspx.cs:53
       System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       System.Web.UI.Page.ProcessRequestMain() +1263 
    怎么回事亚,我用了using System.Web.Util; 
    程序是这样写的:
    private void btnLogin_Click(object sender, System.EventArgs e)
    {SmtpMail.Send("[email protected]","[email protected]", "test", "this is a test");}
    那里出问题了?是SMPT配置吗?应怎样改?
      

  3.   

    应该使用命名空间:System.Web.Mail。请参考如下代码示例:
    using System.Web.Mail;
     
    public struct SendMail
      {
       public String FROM; 
       public String TO; 
       public String CC; 
       public String BCC; 
       public String Subject;
       public String BodyFormat;
       public String Body;
       public MailAttachment Attachment;
      }public bool MailMe(SendMail mail)
      {
       MailMessage msgMail;
       msgMail=new MailMessage();
       
       if ((mail.FROM=="")||(mail.FROM==null))
       {
        return false; 
       }
       
       if ((mail.TO=="")||(mail.TO==null))
       {
        return false;
       }
     
       if ((mail.BodyFormat=="")||(mail.BodyFormat==null))
       {
        msgMail.BodyFormat=MailFormat.Html;  
       }
       else
       {
        msgMail.BodyFormat=MailFormat.Html;  
        if (mail.BodyFormat.ToLower()=="html")
        {
         msgMail.BodyFormat=MailFormat.Html;  
        }
        if(mail.BodyFormat.ToLower()=="text")
        {
         msgMail.BodyFormat=MailFormat.Text;  
        }
       }
       if((mail.CC!="")&&(mail.CC!=null)) msgMail.Cc=mail.CC.ToLower();
       if((mail.BCC!="")&&(mail.BCC!=null)) msgMail.Bcc=mail.BCC.ToLower();    
       msgMail.To=mail.TO.ToLower();  
       msgMail.From=mail.FROM.ToLower();
       msgMail.Subject=mail.Subject;  
       msgMail.Body=mail.Body;
       if (mail.Attachment!=null) msgMail.Attachments.Add(mail.Attachment);
       
       SmtpMail.SmtpServer="smarthost"; 
     
       SmtpMail.Send(msgMail); 
       return true; 
      }
     
    SendMail sm=new SendMail();
    sm.FROM=...
    sm.TO=...
    sm.Body=...
    sm.Subject=....
    MailMe(sm); 你可以在以下MSDN网页找到更多信息:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebMailSmtpMailClassSendTopic.asp
      

  4.   

    还是不行。我添加了SmtpServer的信息(设为本地Smtp Server)
    程序如下:SmtpMail.SmtpServer="birdy"; 
     SmtpMail.Send("[email protected]","[email protected]", "test", "this is a test");系统提示:
    服务器拒绝了一个或多个收件人地址。服务器响应为: 550 5.7.1 Unable to relay for [email protected] 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Runtime.InteropServices.COMException: 服务器拒绝了一个或多个收件人地址。服务器响应为: 550 5.7.1 Unable to relay for [email protected] 
    堆栈跟踪: 
    [COMException (0x8004020f): 服务器拒绝了一个或多个收件人地址。服务器响应为: 550 5.7.1 Unable to relay for [email protected]
    ][TargetInvocationException: 调用的目标发生了异常。]
       System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) +0
       System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) +473
       System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args) +29
       System.Web.Mail.LateBoundAccessHelper.CallMethod(Type type, Object obj, String methodName, Object[] args)
       System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args)[HttpException (0x80004005): 未能访问“CDO.Message”对象。]
       System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args)
       System.Web.Mail.CdoSysHelper.Send(MailMessage message)
       System.Web.Mail.CdoSysHelper.Send(String from, String to, String subject, String messageText)
       System.Web.Mail.SmtpMail.Send(String from, String to, String subject, String messageText)
       app.WebForm1.btnLogin_Click(Object sender, EventArgs e) in i:\yan\asp\app\webform1.aspx.cs:59
       System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       System.Web.UI.Page.ProcessRequestMain() +1263
     
    那位大侠帮忙解决一下。
      

  5.   

    birdy是你的本机机器名?你是否在本机或本机所在的域中安装过Mail Server? 我的意思是你是否靠你的本机就可以将邮件发送到Internet,还是要靠你代码中的[email protected],即163的SMTP服务器。如果你仅仅在本机配置了SMTP Virtual Server,你的邮件必须Relay到smtp.163.com上发送。我认为你的问题在于权限设置上,我配置SMTP服务器也颇费邹则,我有一些建议:1.首先排除你配置本机Virtual Server的问题,确保你有权限使用本机的SMTP Virtual Server2.163的SMTP需要身份认证,所以会产生以上问题,找一个无须身份验证的SMTP Server试试
      

  6.   

    那位能提供一个无须身份验证的SMTP Server?
      

  7.   

    我搞定要要设一下smtp的服务。