代码:
MailMessage mailObj = new MailMessage();mailObj.From = this.txtfrom.Text;
mailObj.To = this.txtto.Text;
mailObj.Subject = "标题";
mailObj.Body = "邮件内容";

mailObj.BodyFormat = MailFormat.Html;
mailObj.Priority = MailPriority.High;
mailObj.Attachments.Add(new MailAttachment("D:\\新建 文本文档.txt"));

SmtpMail.Send(mailObj);运行后出现:
“SendUsing”配置值无效。
这个错误,请问该如何配置呢?

解决方案 »

  1.   

    缺少SmtpMail.SmtpServer = "";//郵件伺服器
      

  2.   

    装SMTP服务,配置下就可以用
      

  3.   

    MailMessage mymail=new MailMessage();//定义email对象
    mymail.BodyFormat=MailFormat.Html;//设置正文格式
    mymail.To=tbemail.Text.Trim();//设置接受的email地址
    mymail.From=webmaster;//设置发件人的email地址
    mymail.Subject=emailtitle;//设置邮件主题
    mymail.Body="fasfsa";//设置邮件正文
    mymail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");//设置支持服务器认证
    mymail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", username);//设置登陆smtp服务器的用户名
    mymail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password);
    System.Web.Mail.SmtpMail.SmtpServer=smtp;//设置smtp服务器
    System.Web.Mail.SmtpMail.Send(mymail);//开始发送
      

  4.   

    那我现在要发送163的邮件 那个SmtpMail.SmtpServer该写什么呢?怎么查smtp的服务器啊
      

  5.   

    //'定义SMTP服务器的名称        
                //m_Mail.SmtpServer = "smtp.163.com";  //2.0中不用也可以
    m_Mail.From = "[email protected] "; ;            // '定义邮件的接收地址             m_Mail.To = " [email protected]";            //'定义邮件的暗送地址             //'m_Mail.Bcc "[email protected]"
                //
                //'定义邮件的抄送地址             // 'm_Mail.Cc = "[email protected]"            //'定义邮件的主题             m_Mail.Subject = "主题";            //'定义邮件的主体             m_Mail.Body = "xxx,hello!欢迎你的加入.";            //'邮件以 HTML的格式发送             m_Mail.BodyFormat = MailFormat.Html;            // '定义邮件的有限级,在此设定为高             m_Mail.Priority = MailPriority.High;            //'给发送的邮件附加上一个附件             //m_Mail.Attachments.Add(new MailAttachment("c:\\A.txt"));
           
                SmtpMail.Send(m_Mail);
      

  6.   

    引入:using System.Web.Mail;
    声明:
    private System.Web.Mail.MailMessage m_Mail;
      

  7.   

    //给你个邮件发送类,看看有用吗
    using System;
    using System.Web.Mail;
    namespace midlink_healthcare
    {

    public class TestMail
    {
    string tb_from;
    string tb_to;
    string tb_mailBody;
    string tb_smtpserver;

    string tb_body;
    string tb_sub;
    public  TestMail(string to ,string body,string sub)
    {
    tb_to=to.Trim();
    //tb_name=name.Trim();
    tb_body=body.Trim();
    tb_sub=sub.Trim();
    } public void sengmill_net()
    {


    tb_from="[email protected]";//你使用的邮箱名字

    tb_mailBody=tb_body;
    tb_smtpserver="xxx.xx.xxx.xxx";//你使用的邮件服务器的ip地址
    System.Web.Mail.MailMessage mailmsg = new System.Web.Mail.MailMessage();
    mailmsg.From = tb_from;
    mailmsg.To   = tb_to;
    mailmsg.Body = tb_mailBody;
    mailmsg.Subject =tb_sub;


    mailmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
    //是否需要验证,一般是要的    
    mailmsg.Fields.Add ("http://schemas.microsoft.com/cdo/configuration/sendusername", "xxxxx"); 
    //自己邮箱的用户名    
    mailmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "xxxxxxx");
    //自己邮箱的密码 
    System.Web.Mail.SmtpMail.SmtpServer = tb_smtpserver;
    System.Web.Mail.SmtpMail.Send(mailmsg);
    } }
    }
      

  8.   

    你实例化一个这个类,然后直接调用sengmill_net()发放就可以了.
      

  9.   

    你这个tb_smtpserver还是要赋值的啊~~~问题是我 现在如果发163的邮件 不知道设置smtp服务器啊  有人知道吗?
      

  10.   

    我加了SmtpMail.SmtpServer = "smtp.163.com";也不行啊 郁闷我现在的程序是:
    MailMessage mailObj = new MailMessage(); mailObj.From = this.txtfrom.Text;
    mailObj.To = this.txtto.Text;
    mailObj.Subject = "标题";
    mailObj.Body = "邮件内容"; mailObj.BodyFormat = MailFormat.Html;
    mailObj.Priority = MailPriority.High;
    mailObj.Attachments.Add(new MailAttachment("D:\\新建 文本文档.txt"));

    mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
    mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "wangzhaoli1982");
    mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "XXXXXXX"); SmtpMail.SmtpServer = "smtp.163.com";
    SmtpMail.Send(mailObj);结果还是不行
      

  11.   

    //我这段代码可以呀.我刚刚还发送成功了.
    using System;
    using System.Web.Mail;
    namespace XXXX
    {
    /// <summary>
    /// TestMail 的摘要说明。
    /// </summary>
    public class TestMail
    {
    string tb_from;
    string tb_to;
    string tb_mailBody;
    string tb_smtpserver;
    //string tb_name;
    string tb_body;
    string tb_sub;
    public  TestMail(string to ,string body,string sub)
    {
    tb_to=to.Trim();
    //tb_name=name.Trim();
    tb_body=body.Trim();
    tb_sub=sub.Trim();
    } public void sengmill_net()
    {


    tb_from="[email protected]";

    tb_mailBody=tb_body;
    tb_smtpserver="smtp.163.com";
    System.Web.Mail.MailMessage mailmsg = new System.Web.Mail.MailMessage();
    mailmsg.From = tb_from;
    mailmsg.To   = tb_to;
    mailmsg.Body = tb_mailBody;
    mailmsg.Subject =tb_sub;


    mailmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
    //是否需要验证,一般是要的    
    mailmsg.Fields.Add ("http://schemas.microsoft.com/cdo/configuration/sendusername", "XXXXXX"); 
    //自己邮箱的用户名    
    mailmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "XXXXX");
    //自己邮箱的密码 
    System.Web.Mail.SmtpMail.SmtpServer = tb_smtpserver;
    System.Web.Mail.SmtpMail.Send(mailmsg);
    } }
    }////调用代码
    TestMail t=new TestMail("对方email地址","邮件内容","标题");
    t.sengmill_net();
      

  12.   

    Donny_zhang(海豚) ( ) 我按你的试了
    是这个结果还是不行 你还做了别的什么吗邮件无法发送到 SMTP 服务器。传输错误代码为 0x800ccc15。服务器响应为 not available 调用代码:
    TestMail t=new TestMail("[email protected]","邮件内容","标题");
    t.sengmill_net();
    你的类我写成:
    public class TestMail
    {
    string tb_from;
    string tb_to;
    string tb_mailBody;
    string tb_smtpserver;
    //string tb_name;
    string tb_body;
    string tb_sub;
    public  TestMail(string to ,string body,string sub)
    {
    tb_to=to.Trim();
    //tb_name=name.Trim();
    tb_body=body.Trim();
    tb_sub=sub.Trim();
    } public void sengmill_net()
    {


    tb_from="[email protected]";

    tb_mailBody=tb_body;
    tb_smtpserver="smtp.163.com";
    System.Web.Mail.MailMessage mailmsg = new System.Web.Mail.MailMessage();
    mailmsg.From = tb_from;
    mailmsg.To   = tb_to;
    mailmsg.Body = tb_mailBody;
    mailmsg.Subject =tb_sub;


    mailmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
    //是否需要验证,一般是要的    
    mailmsg.Fields.Add ("http://schemas.microsoft.com/cdo/configuration/sendusername", "wangzhaoli1982"); 
    //自己邮箱的用户名    
    mailmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "XXXXX");
    //自己邮箱的密码 
    System.Web.Mail.SmtpMail.SmtpServer = tb_smtpserver;
    System.Web.Mail.SmtpMail.Send(mailmsg);
    }
      

  13.   

    下个JMAIL组建吧。。一网都是,LZ可以去看看,随便搜搜,到处都是方法..
      

  14.   

    /// <summary>
            /// 发送邮件
            /// </summary>
            /// <param name="strSmtpServer">smtp地址</param>
            /// <param name="UserName">用户名</param>
            /// <param name="Password">密码</param>
            /// <param name="strFrom">发信人地址</param>
            /// <param name="strto">收信人地址</param>
            /// <param name="strSubject">邮件标题</param>
            /// <param name="strBody">邮件正文</param>
            public static void SendMail(string strSmtpServer, string UserName, string Password, string strFrom, string strto, string strSubject, string strBody, string strFileName)
            {
                //生成一个 使用SMTP发送邮件的客户端对象
                System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(strSmtpServer);            //表示以当前登录用户的默认凭据进行身份验证
                client.UseDefaultCredentials = true;                 //包含用户名和密码
                client.Credentials = new System.Net.NetworkCredential(UserName, Password);             //指定如何发送电子邮件。
                 //Network                      电子邮件通过网络发送到 SMTP 服务器。  
                 //PickupDirectoryFromIis       将电子邮件复制到挑选目录,然后通过本地 Internet 信息服务 (IIS) 传送。  
                 //SpecifiedPickupDirectory     将电子邮件复制到 SmtpClient.PickupDirectoryLocation 属性指定的目录,然后由外部应用程序传送。              client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;            //建立邮件对象 
                System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(strFrom, strto, strSubject,strBody);
                
                //定义邮件正文,主题的编码方式
                message.BodyEncoding = System.Text.Encoding.GetEncoding("gb2312");
                message.SubjectEncoding = System.Text.Encoding.GetEncoding("gb2312");
               
                //获取或设置一个值,该值指示电子邮件正文是否为 HTML。 
                message.IsBodyHtml = false;
                
                //指定邮件优先级
         
                message.Priority = System.Net.Mail.MailPriority.Normal;            //添加附件
                //System.Web.Mail.MailAttachment mailAttachment=new System.Web.Mail.MailAttachment(@"f:/baihe.txt"); 
                if (strFileName != "" && strFileName != null)
                {
                    Attachment data = new Attachment(strFileName);
                    message.Attachments.Add(data);
                }
              
                
                //发件人身份验证,否则163 发不了
                client.Credentials =  new System.Net.NetworkCredential(strFrom, Password)
                //发送
                client.Send(message);
            }===================================vs2005  调试通过
      

  15.   

    晕,是mcafee 把。我当时也是。^_^
      

  16.   

    junzhang4008
    的代码测试通过