System.Net.Mail.SmtpClient mail = new System.Net.Mail.SmtpClient();
            mail.Host = "mail.host.com";      //smtp
            mail.Credentials = new System.Net.NetworkCredential(UserName, Password);
            mail.Timeout = 100;
            mail.EnableSsl = true;              //发送连接套接层是否加密             System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
            MailAddress mailaddrFrom = new MailAddress("[email protected]");
            MailAddress mailaddrTo = new MailAddress("[email protected]");
            message.From = mailaddrFrom;         
            message.To.Add(mailaddrTo);
            message.Subject = "   ";
            message.Body = "      ";
            message.SubjectEncoding = System.Text.Encoding.GetEncoding("gb2312");
            message.BodyEncoding = System.Text.Encoding.GetEncoding("gb2312");
            message.IsBodyHtml = true;
            try
            {
                mail.Send(message);
                JScript.ShowMessage(this.Page, "您的信息已发送,请查收!");
             }
            catch (Exception ex)
            {
                JScript.ShowMessage(this, ex.Message);
            }
            finally
            {
            }

解决方案 »

  1.   

    基本上COPY 上面的代码,结果错误一样:
    Error:邮箱不可用。 服务器响应为: Óû§±»Ëø¶¨ Type:System.Net.Mail.SmtpException
      

  2.   

    这说明是不是我的系统设置的问题呢?系统:WIN2003
      

  3.   

    我用jmail ,都发/接了N封了!
      

  4.   

    原来我用jmail,在本机上可以发,可是部署到目标计算机上时,就发不出,有人说目标计算机要安装jmail,可以我的安装了jmail也不行,不知道怎么搞,
      

  5.   

    不是程序问题/
    你换个Email ,可以去sina申请一个
      

  6.   

    /*******************************
    *
    *  文件名:SendEmail.cs
    *  copyright(C) 2007-2008 星星
    *  文件编号:01
    *  创 建 人:星星
    *  日    期:2007-05-31
    *  修 改 人:星星
    *  日    期:2007-05-31
    *  描    述:发送Email的类
    *
    ********************************/namespace SendMail
    {
        using System;
        using System.Net;
        using System.Net.Mail;
        using System.Net.Configuration;
        using System.Web.Configuration;
        /// <summary>
        /// 可以发送多种邮件
        ///  gmail的smtp采用了ssl连接:   ([email protected],[email protected])
        ///  Outgoing Mail (SMTP) Server - requires TLS: smtp.gmail.com (use authentication)
        ///  Use Authentication: Yes
        ///  Use STARTTLS: Yes (some clients call this SSL)
        ///  Port: 465 or 587, 25
        ///  其他的 port设为<0则使用默认的 Use STARTTLS: no
        /// </summary>
        public class EMail
        {
            private string m_Host;//smtp.gmail.com
            private int m_Port, m_Encoding; //端口,编码
            private bool m_EnableSsl, m_IsBodyHtml, m_defaultCredentials; //加密, HTMl格式,身份验证
            private string m_SmtpUserName, m_SmtpUserPassword,m_FromMail;        /// <summary>
            /// 用于web.config中已经配置好邮件帐号
            /// </summary>
            public EMail()
            {
                this.m_EnableSsl    = false;
                this.m_IsBodyHtml   = false;
                this.m_Encoding     = 936;            //从web.config读取邮件配置
                System.Configuration.Configuration config   = WebConfigurationManager.OpenWebConfiguration("~/");
                MailSettingsSectionGroup mailSettings       = (MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");
                this.m_SmtpUserName         = mailSettings.Smtp.Network.UserName;
                this.m_SmtpUserPassword     = mailSettings.Smtp.Network.Password;
                this.m_FromMail             = mailSettings.Smtp.From;
                this.m_defaultCredentials   = mailSettings.Smtp.Network.DefaultCredentials;
            }        /// <summary>
            /// 直接设置邮件帐号
            /// </summary>
            /// <param name="Port">0为默认设置</param>
            public EMail(string SmtpUserName, string SmtpUserPassword, string Host, int Port, bool DefaultCredentials)
            {
                this.m_Host     = Host;
                this.m_Port     = Port;
                this.m_Encoding = 936;
                this.m_EnableSsl    = false;
                this.m_IsBodyHtml   = false;
                this.m_EnableSsl    = false;
                this.m_defaultCredentials   = DefaultCredentials;
                this.m_SmtpUserName         = SmtpUserName;
                this.m_SmtpUserPassword     = SmtpUserPassword;
            }        //是否以HTML格式发送
            public bool IsBodyHtml
            {
                set { this.m_IsBodyHtml = value; }
                get { return this.m_IsBodyHtml; }
            }        //编码方式
            public int Encoding
            {
                set { this.m_Encoding = value; }
                get { return this.m_Encoding; }
            }        //是否加密
            public bool EnableSsl
            {
                set { this.m_EnableSsl = value; }
                get { return this.m_EnableSsl; }
            }        /// <summary>
            ///直接设置邮件帐号的发送方法 return: true ,false
            /// </summary>
            /// <param name="CC, Bcc, FileName">可以为null</param>
            public bool Send(string From, string To, string Subject, string Body, string[] CC, string[] Bcc, string FileName)
            {
                //Create MailMessage
                MailMessage mailMessage = new MailMessage(From, To, Subject, Body);
                mailMessage.IsBodyHtml = this.m_IsBodyHtml;                                             //Body is Html
                mailMessage.SubjectEncoding = System.Text.Encoding.GetEncoding(this.m_Encoding);        //Mail Subject Encoding
                mailMessage.BodyEncoding = System.Text.Encoding.GetEncoding(this.m_Encoding);           //Mail Body Encoding
                
                if (!String.IsNullOrEmpty(FileName))
                {   // add accessories
                    mailMessage.Attachments.Add(new Attachment(FileName));
                }
                if (CC != null && CC.Length > 0)
                {
                    foreach (string ccAddress in CC)
                    {
                        mailMessage.CC.Add(new MailAddress(ccAddress));
                    }
                }
                if (Bcc != null && Bcc.Length > 0)
                {
                    foreach (string bccAddress in Bcc)
                    {
                        mailMessage.Bcc.Add(bccAddress);
                    }
                }            //Send Email
                SmtpClient smtpClient = new SmtpClient(this.m_Host);
                if (this.m_Port > 0)
                    smtpClient.Port = this.m_Port;            smtpClient.EnableSsl = this.m_EnableSsl;
                try
                {
                    if (this.m_defaultCredentials) //要身份验证
                        smtpClient.Credentials = new NetworkCredential(this.m_SmtpUserName, this.m_SmtpUserPassword);
                    smtpClient.Send(mailMessage);
                    return true;
                }
                catch
                {
                    return false;
                }
            }        /// <summary>
            /// 用于web.config中已经配置好邮件帐号 的发送方法 return: true ,false
            /// </summary>
            /// <param name="CC, Bcc, FileName">可以为null</param>
            public bool Send( string To, string Subject, string Body, string[] CC, string[] Bcc, string FileName)
            {
                //Create MailMessage
                MailMessage mailMessage = new MailMessage(m_FromMail, To, Subject, Body);
                mailMessage.IsBodyHtml = this.m_IsBodyHtml;                                             //Body is Html
                mailMessage.SubjectEncoding = System.Text.Encoding.GetEncoding(this.m_Encoding);        //Mail Subject Encoding
                mailMessage.BodyEncoding = System.Text.Encoding.GetEncoding(this.m_Encoding);           //Mail Body Encoding            if (!String.IsNullOrEmpty(FileName))
                {   // add accessories
                    mailMessage.Attachments.Add(new Attachment(FileName));
                }
                if (CC != null && CC.Length > 0)
                {
                    foreach (string ccAddress in CC)
                    {
                        mailMessage.CC.Add(new MailAddress(ccAddress));
                    }
                }
                if (Bcc != null && Bcc.Length > 0)
                {
                    foreach (string bccAddress in Bcc)
                    {
                        mailMessage.Bcc.Add(bccAddress);
                    }
                }            //Send Email
                SmtpClient smtpClient = new SmtpClient(this.m_Host);
                smtpClient.EnableSsl = this.m_EnableSsl;
                try
                {
                    if (this.m_defaultCredentials)      //要身份验证
                        smtpClient.Credentials = new NetworkCredential(this.m_SmtpUserName, this.m_SmtpUserPassword);
                    smtpClient.Send(mailMessage);
                    return true;
                }
                catch
                {
                    return false;
                }
            }
        }}
      

  7.   


    using System;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using SendMail;public partial class SendEmail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {    }
        protected void Btn_Click(object sender, EventArgs e)
        {
            string strEmailAdr = "[email protected]", strShow;        /*//邮件直接配置
            EMail mail = new EMail("aspnetxm", "aspnet1212", "smtp.gmail.com", 25,true);
            bool bResult = mail.Send("[email protected]", strEmailAdr, "测试Gmail", "ok", null, null, null);
            */        //邮件在web.config中配置
            EMail mail = new EMail();
            mail.EnableSsl = true;
            bool bResult = mail.Send( strEmailAdr, "测试Gmail", "ok", null, null, null);
            
            if (bResult)
               strShow = "邮件发送成功。";
            else
                strShow = "邮件发送失败";        Response.Write(strShow);
            
        }
    }
    几天前刚用过sina ,gmail都可以
      

  8.   

    SmtpClient类
    UseDefaultCredentials = false;
      

  9.   

    我说一句,我用net2.0试验过,新申请的邮箱不管是sina还是sohu,126,163好像都发送不成功,网关拒绝访问,用以前(也就是老早申请的邮箱)就没有问题!
    这也让我郁闷一会!
      

  10.   

    我的屡试不爽,
    http://www.cnblogs.com/ustbwuyi/archive/2007/05/28/762581.html
      

  11.   

    小弟也遇到了,VS2005password recovery控件就是找通过邮件回密码那块,我用163 sina 126 的都不行。有没有仁兄解决了的??
      

  12.   

    可能是你的smtp服务器的问题 又时候会拒收 有时需要验证 或者加密的
      

  13.   

    smtp服务器是需要验证的,这样你的发送邮件不能用jmail,只能用net2。0有个类可以自己写
      

  14.   

    同意LS,我求职的时候,顺手用asp.net搞了一个群发邮件的东东寄简历,也是用的asp.net2.0的控件,那时我也才开始学asp.net,不过效果不佳,好象发了一百封,才有一家有回信.呵呵
      

  15.   

    估计跟我遇到的问题一样
    http://www.lemongtree.com/Archives/SmtpClient.aspx
      

  16.   

    还是jmail 用起来简单欢迎访问我的视频搜索引擎:http://www.vzhangmen.com
      

  17.   

    去这里看看 http://systemnetmail.com/
      

  18.   

    163的好像現在是不行了,申請個sina的吧。