try
        {
            MailMessage objMail = new MailMessage();            //发件人地址
            objMail.From = new MailAddress("[email protected]");
            //邮件标题
            objMail.Subject = "sadsadsadsa";
            //邮件标题编码 
            objMail.SubjectEncoding = System.Text.Encoding.UTF8;
            //邮件内容
            objMail.Body = "asdsadsa";
            //邮件内容编码 
            objMail.BodyEncoding = System.Text.Encoding.UTF8;
            //收件人地址在这里可以加多个
            objMail.To.Add("[email protected]");
            //用SMTP发送邮件的方式
            SmtpClient client = new SmtpClient();
            //用户名和密码
            client.Credentials = new System.Net.NetworkCredential("zywcy100", "6745300");
            //服务器名
            client.Host = "SMTP.163.com";
            //发送
            client.Send(objMail);
            ClientScriptManager csm = this.ClientScript;
            csm.RegisterStartupScript(this.GetType(), "sufei", "发送成功");
        }
        catch (Exception ex)
        {
            ClientScriptManager csm = this.ClientScript;
            csm.RegisterStartupScript(this.GetType(), "sufei", ex.Message.ToString().Trim());
        }
出现错误:
邮箱不可用。 服务器响应为: Óû§±»Ëø¶¨

解决方案 »

  1.   

    给你一个发送邮件的方法,我以前写的:
        #region 发送Web邮件和附件
            /// <summary>
            /// 发送Web邮件和附件
            /// </summary>
            /// <param name="mailFrom">发送邮件邮箱地址</param>
            /// <param name="mailTo">接收邮件的邮箱地址</param>
            /// <param name="mailSubject">邮件主题</param>
            /// <param name="mailBody">邮件内容</param>
            /// <param name="mailFilePath">发送邮件附件</param>
            /// <returns></returns>
            public  bool SendWebMail(string mailFrom, string mailTo, string mailSubject, string mailPassWord, string mailBody, string[] mailFilePath)
            {
                MailMessage mail = new MailMessage();
                mail.From = mailFrom; 
                mail.To = mailTo;
                mail.Subject = mailSubject;
                mail.Body = mailBody;
                mail.BodyFormat = MailFormat.Html;//设置为HTML格式
                string[] mailSmtp = Regex.Split(mailFrom, "@", RegexOptions.IgnoreCase);
                mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
                mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", mailSmtp[0]); //set your username here
                mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", mailPassWord); //set your password here
                SmtpMail.SmtpServer = mailSmtp[1].Insert(0, "smtp.");
                string[] file = mailFilePath;
                foreach (string filePath in file)
                {
                    if (filePath != "")
                    {
                        mail.Attachments.Add(new MailAttachment(filePath));
                    }
                }
                try
                {
                    SmtpMail.Send(mail);
                    return true;
                }
                catch
                {
                    return false;
                }
            }
            #endregion
    如果不带附件的话就传一个空的字符串数组过去。
      

  2.   

    先要引入命名空间 :using System.Text.RegularExpressions
    using System.Web.Mail;
      

  3.   

    之前正好有做邮件发送的项目,也研究了很久,当然,也同样碰到过和LZ一样的问题,而不同STMP服务器返回的错误信息也千奇百怪,现把我的经验和LZ分享(仅说STMP的):1、163的和126的邮箱,这是我首先测试,结果测试结果发下2005年之前注册的都绝对可以使用,而之后有的可以有的却没有理由的不可以,我的主要配置如下:
    发件人地址="[email protected]"
    SMTP服务器地址="smtp.126.com
    邮箱账号="fajianren"
    邮箱密码="mima"(注意,发件人身份验证,否则163发不了)
    端口号="25"(注意,这个最好给设置上)2、Hotmail的邮箱,我后来测试后发现,稳定性上比163和126的要高的多,主要配置方法和上面没有区别,只是Hotmail的端口号是默认的,似乎可以不用设置;3、sohu.com邮箱,我测试了之后的结果是:稳定性处于以上两个之间;
    所以,最后,我解决办法是:
    用了2个Try块嵌套,试图发送两次(如果第一次不成功的话再进行第二次发送),后来测试证明:100%成功,我最后选择用了hotmail的账号和2005年之前注册的一个账号(备用),Try的基本代码即:try
    {
        KLEMail.SendMail(theSMTPServer, theSMTPUserName, theSMTPPassWord, theSMTPEMail, txtemail.Text.Trim(), theEmailTitle, theEmailContent, "");
    }
    catch
    {
        try
        {
            KLEMail.SendMail(theSMTPServer, theSMTPUserName, theSMTPPassWord, theSMTPEMail, txtemail.Text.Trim(), theEmailTitle, theEmailContent, "");
        }
        catch
        {    }
    }
    另外说明:虽然我知道频繁的使用try块肯定会影响代码的执行效率,但是,毕竟我们的客户首先要的是程序能够成功运行
    ,所以基于SMTP天生的邮箱发送不稳定性,所以我也只能这样写了。