protected void Button1_Click(object sender, EventArgs e)
    {
        MailAddress MessageFrom = new MailAddress("[email protected]");  //发件人邮箱地址 
        string MessageTo = "[email protected]";  //收件人邮箱地址 
        string MessageSubject = "测试例子";        //邮件主题 
        string MessageBody = "测试的例子终于成功了,很开心啊!";    //邮件内容 
        if (Send(MessageFrom, MessageTo, MessageSubject, MessageBody))
        {
            Response.Write("发送邮件成功");
        }
        else
        {
            Response.Write("发送邮件失败");
        }
    }
    public bool Send(MailAddress MessageFrom, string MessageTo, string MessageSubject, string MessageBody)
    {
        MailMessage message = new MailMessage();
        message.From = MessageFrom;
        //收件人邮箱地址可以是多个以实现群发
        message.To.Add(MessageTo);
        message.Subject = MessageSubject;
        message.Body = MessageBody;
        //是否为html格式
        message.IsBodyHtml = true;
        //发送邮件的优先等级 
        message.Priority = MailPriority.High;        SmtpClient sc = new SmtpClient();
        //指定发送邮件的服务器地址或IP,根据不同的邮件服务商,写不同的服务器名
        //smtp.Sina.com
        sc.Host = "smtp.qq.com";
        //指定发送邮件端口 
        //sc.Port = 587;                         
        sc.UseDefaultCredentials = true;
        sc.EnableSsl = true;        //指定登录服务器的用户名和密码 
        sc.Credentials = new System.Net.NetworkCredential("601458703", "852258");
        try
        {
            //发送邮件 
            sc.Send(message);
        }
        catch (Exception e)
        {
            Response.Write(e.Message);
            return false;
        }
        return true;
    }
错误提示:服务器不支持安全连接。发送邮件失败

解决方案 »

  1.   


    //sc.EnableSsl = true;
    sc.EnableSsl = false;
      

  2.   


    应该是这个问题,不行的话,sc.UseDefaultCredentials = true;给改成false再试试
      

  3.   

    client.Credentials = new System.Net.NetworkCredential("用户名", "密码"); 
    货mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "");   mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", ""); 
      

  4.   

    //一:用自己的服务器作为邮件服务器时:
    //如出现:邮箱不可用。 服务器响应为: 5.7.1 Unable to relay for ***@gmail.com
    //解决办法如下:在IIS中,右击“默认SMTP虚拟服务器”,选择“属性”,切换到“访问”页,点击“中继”按钮,在弹出框中选择“仅以下列表除外”,确定。
    //二:用其它的邮件服务器发送,经测试大多数免费邮箱都不提供SMTP服务,用qq邮箱的就可以,方法:进入qq邮箱-->设置-->帐户-->开通POP3/IMAP/SMTP服务,即可用smtp.qq.com作为邮件服务器了,可用它来发送邮件using System;
    using System.Data;
    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 System.Net.Mail;public partial class _Default : System.Web.UI.Page
    {
      protected void Page_Load(object sender, EventArgs e)
      {  }  public void SendSMTPEMail(string strSmtpServer, string strFrom, string strFromPass, string strto, string strSubject, string strBody)
      {
      System.Net.Mail.SmtpClient client = new SmtpClient(strSmtpServer);
      client.UseDefaultCredentials = false;
      client.Credentials = new System.Net.NetworkCredential(strFrom, strFromPass);
      client.DeliveryMethod = SmtpDeliveryMethod.Network;
      System.Net.Mail.MailMessage message = new MailMessage(strFrom, strto, strSubject, strBody);
      message.BodyEncoding = System.Text.Encoding.UTF8;
      message.IsBodyHtml = true;
      client.Send(message);
      }
      //第一个参数是邮箱服务器
      //第二个参数发件人的帐号
      //第三个参数发件人密码
      //第四个参数收件人帐号
      //第五个参数主题
      //第六个参数内容.
      protected void Button1_Click(object sender, EventArgs e)
      {//发送邮件
      try
      {
      //SendSMTPEMail("nz.oicp.net", "[email protected]", "123", "[email protected]", "123", "用asp.net发送邮件,用自己的邮件服务器,测试成功");
      SendSMTPEMail("smtp.qq.com", "[email protected]", "123xxxxxxx", "[email protected]", "123", "用asp.net发送邮件,用qq的smtp.qq.com服务器,测试成功");  }
      catch (Exception er)
      {
      Label1.Text = er.Message;
      }
      }
    }
      

  5.   

    http://blog.csdn.net/abandonship/archive/2008/12/23/3580975.aspx
      

  6.   


    /// <summary>
        /// 邮件类by Zr
        /// </summary>
        public class MailSender
        {
            /// <summary>
            /// 邮件类by Zr
            /// </summary>
            /// <param name="tomailAddress">收件人的邮箱地址</param>
            /// <param name="subject">标题</param>
            /// <param name="body">正文</param>
            /// <param name="isBodyHtml">正文是否是HTML格式</param>
            /// <param name="files">附件,可为NULL</param>
            public static void Send(MailAddressCollection mac, string subject, string body, bool isBodyHtml, params string[] files)
            {
                try
                {
                    //mail服务器设置
                    SmtpClient mailserver = new SmtpClient();                SmtpSection cfg = NetSectionGroup.GetSectionGroup(WebConfigurationManager.OpenWebConfiguration("~/web.config")).MailSettings.Smtp;
                    mailserver.Host = cfg.Network.Host;   //发送邮件的邮件服务器;                mailserver.Credentials = new System.Net.NetworkCredential(cfg.Network.UserName, cfg.Network.Password);//发送邮件的账号和密码                mailserver.Timeout = 50000;
                    mailserver.EnableSsl = false;                //mail邮件设置
                    using (MailMessage mail = new MailMessage())
                    {
                        MailAddress mfrom = new MailAddress(cfg.Network.UserName);
                        mail.From = mfrom;
                        foreach (MailAddress tomailAddress in mac)
                        {
                            mail.To.Add(tomailAddress);//收件人的邮箱地址
                        }                    mail.Subject = subject;//标题
                        mail.SubjectEncoding = System.Text.Encoding.GetEncoding("GB2312");
                        mail.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");
                        mail.IsBodyHtml = isBodyHtml;//是否是HTML格式
                        mail.Body = string.Format(@body);
                        mail.Attachments.Clear();
                        if (files != null && files.Length != 0)
                        {
                            for (int i = 0; i < files.Length; ++i)
                            {
                                Attachment attach = new Attachment(files[i]);
                                mail.Attachments.Add(attach);
                            }
                        }
                        mailserver.Send(mail);
                    }
                }
                catch
                {
                    JsUtil.ShowMsg("网络延迟,请稍后在发送邮件!!");
                }        } 
        }用我的测试可用,