using System.web.Mail;             MailMessage msg = new MailMessage();
            //发送方地址(如[email protected]
            msg.From = "[email protected]";
            //接收方地址(如[email protected]
            msg.To = "[email protected]";
            //正文内容类型 
            msg.BodyFormat = MailFormat.Html;
            //正文内容编码 
            msg.BodyEncoding = System.Text.Encoding.Default;
            //主题 
            msg.Subject = "张大宇向您问好";
            //内容 
            msg.Body = "<html><head><META content=zh-cn http-equiv=Content-Language><meta http-equiv='Content-Type' content='text/html; charset=gb2312'><style type=text/css>A:link { FONT-SIZE: 9pt; TEXT-DECORATION: none; color: #000000}A:visited {FONT-SIZE: 9pt; TEXT-DECORATION: none; color: #666666}A:hover {COLOR: #ff6600; FONT-SIZE: 9pt; TEXT-DECORATION: underline}BODY {FONT-SIZE: 9pt} --></style></head><body><font color=red>用户名:" + UserName.Text.Trim() + "</font><br><font color=green>密码:" + strUserPsw.ToString() + "</font><br><b>验证地址:</b><a href='http://192.168.1.98/AllFiles/Member/CheckFromEmail.aspx?UserName=" + UserName.Text.Trim() + "'target=_blank>http://192.168.1.98/AllFiles/Member/CheckFromEmail.aspx?UserName=" + UserName.Text.Trim() + "</a>。如果您不能点击链接进行跳转,请把这个地址粘贴到浏览器的地址栏直接访问。<br><font color=red>此邮件不必回复,谢谢。</font></body></html>";
            //设置为需要用户验证 
            msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
            //设置验证用户名 
            msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "zdyguilong");
            //设置验证密码 
            msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "123456");
            //邮件服务器地址(如smtp.163.com) 
            SmtpMail.SmtpServer = "smtp.163.com";
            //发送 
            SmtpMail.Send(msg);
            //Response.Write("<script language='javascript'>alert('注册成功');window.location='../default.aspx'</script>");

解决方案 »

  1.   

    设置.UseDefaultCredentials = true;表示以当前登录用户的默认凭据进行身份验证
    smtp.21cn.com上面有这个用户吗?
      

  2.   

    /*****************************************/
    /* Project name: MailDaemon              */
    /* Module name: Mail Sender              */
    /* Author: Ming Yeh                      */
    /* Created date: 2006-08-21              */
    /* Last modified by:                     */
    /* Last modify date:                     */
    /*                .-._                   */
    /*               {_}^ )o                 */
    /*      {\________//~`                   */
    /*       (         )                     */
    /*       /||~~~~~||\                     */
    /*      |_\\_    \\_\_                   */
    /*                                       */
    /*****************************************/
    using System;
    using System.Collections.Generic;
    using System.Net;
    using System.Net.Mail;
    using System.Text;namespace mailDaemon
    {
        class MailSender
        {
            private const string SERVER_IP = "61.181.255.80";
            private const string SENDER_EMAIL = "[email protected]";
            private const string USERNAME = "mailist";
            private const string PASSWORD = "bu2kwh1at";
            private const string SUBJECT = "高速路商机速递";
            string _server;
            string _senderEmail;
            string _username;
            string _password;
            static bool mailSent = false;        public MailSender(string server, string senderEmail, string username, string password)
            {
                _server = server;
                _senderEmail = senderEmail;
                _username = username;
                _password = password;
            }
            public MailSender():this(SERVER_IP, SENDER_EMAIL, USERNAME, PASSWORD)
            {
                
            }
            public void SendMail(string email, string content)
            {
                MailMessage msg = new MailMessage(_senderEmail, email, SUBJECT, content);
                msg.BodyEncoding = Encoding.UTF8;
                msg.Priority = MailPriority.High;
                msg.IsBodyHtml = true;
                SmtpClient client = new SmtpClient(_server);
                NetworkCredential credential = new NetworkCredential(_username, _password);
                client.UseDefaultCredentials = false;
                client.Credentials = credential;
                client.SendCompleted += new SendCompletedEventHandler(client_SendCompleted);
                client.SendAsync(msg, "Message Sent.");
                Console.WriteLine(email + "邮件发送中,按C取消发送");
                //string answer = Console.ReadLine();
                //if (answer.StartsWith("c") && mailSent == false)
                //{
                //    client.SendAsyncCancel();
                //}
                Console.WriteLine(email + "处理完成");
            }        void client_SendCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
            {
                String token = (string)e.UserState;            if (e.Cancelled)
                {
                    Console.WriteLine("[{0}] Send canceled.", token);
                }
                if (e.Error != null)
                {
                    Console.WriteLine("[{0}] {1}", token, e.Error.ToString());
                }
                else
                {
                    Console.WriteLine("Message sent.");
                }
                mailSent = true;
            }
        }
    }
      

  3.   

    http://blog.csdn.net/liushengpiaoxu/archive/2007/02/12/1508548.aspx 参考一下这个函数,我测试过了,没问题.