我网站想实现一个,用户注册后自动回复用户一邮件进行确认。!~但是由于是菜鸟,在网上面收了很多类似system.web.mail的一些代码,我自己有点儿看不懂,所以希望大家给我解说一下。希望贴代码+注释最好了。我在这里感谢大家了。如果方便,我把QQ留下804172665如果有心的加我哦。谢谢

解决方案 »

  1.   

    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.Web.Util;
    using System.Web.Mail;
    /// <summary>
    ///SendMail 的摘要说明
    /// </summary>public class SendMail
    {
     public SendMail()
     {
      //
      //TODO: 在此处添加构造函数逻辑
      //
     }
        /// <summary>
        ///SendMail 的摘要说明
        /// </summary>
        /// <param name="fromMail">发件人</param>
        /// <param name="toMail">收件人</param>
        /// <param name="ccMail">抄送人</param>
        /// <param name="bccMail">暗送人</param>
        /// <param name="subject">主题</param>
        /// <param name="body">内容</param>
        /// <param name="sendMode">模式</param>
        /// <returns>查询结果(bool)是否成功</returns>
        public bool WriteAndSendMail(string fromMail, string toMail, string ccMail, string bccMail, string subject, string body, string sendMode)
        {
            try
            {
                MailMessage myMail = new MailMessage();
                myMail.From = "[email protected]";// fromMail;//发件人
                myMail.To = fromMail;//收件人
                myMail.Cc = ccMail;//抄送人
                myMail.Bcc = bccMail;//暗送人
                myMail.Subject = subject;//主题
                myMail.Body = body;
                myMail.BodyFormat = sendMode == "0" ? MailFormat.Text : MailFormat.Html;
                //附件
                //string ServerFileName = "";
                //if (this.upfile.PostedFile.ContentLength != 0)
                //{
                //    string upFileName = this.upfile.PostedFile.FileName;
                //    string[] strTemp = upFileName.Split('.');
                //    string upFileExp = strTemp[strTemp.Length - 1].ToString();
                //    ServerFileName = Server.MapPath(DateTime.Now.ToString("yyyyMMddhhmmss") + "." + upFileExp);
                //    this.upfile.PostedFile.SaveAs(ServerFileName);
                //    myMail.Attachments.Add(new MailAttachment(ServerFileName));
                //}
                myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);
                myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "sunshijie110"); //发送方邮件帐户
                myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "****"); //发送方邮件密码
                SmtpMail.SmtpServer = "smtp.126.com";
                SmtpMail.Send(myMail);
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
      

  2.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Net;
    using System.Net.Mail;namespace WindowsFormsApp_csMailSend
    {
        public static class Mail
        {
            public static bool SendMail(string FromMail,string PassWord,string SmtpServer,string ToMail,string Subject,string Body,string AddFile)
            {
                try
                {
                    SmtpClient objSmtpClient = new SmtpClient();//("[email protected]",25
                    objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
                    objSmtpClient.Host = SmtpServer;
                    objSmtpClient.Credentials = new NetworkCredential(FromMail.Split('@').GetValue(0).ToString(), PassWord);                MailMessage objMail = new MailMessage(FromMail,ToMail);
                    objMail.Body = Body;
                    objMail.Subject = Subject;                if (AddFile != "")
                    {
                        Attachment objAttachment = new Attachment(AddFile);
                        objMail.Attachments.Add(objAttachment);
                    }                objSmtpClient.Send(objMail);                return true;
                }
                catch
                {
                    return false;
                }
            }
        }
    }
      

  3.   

        private void btSend_Click(object sender, EventArgs e)
            {
                if (Mail.SendMail(tbFromMail.Text, tbpassword.Text, tbSmtpServer.Text, tbToMail.Text, tbobj.Text, tbbody.Text, tbAddFile.Text))
                {
                    MessageBox.Show("邮件发送成功!", "系统提示", MessageBoxButtons.OK,MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("邮件发送失败!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
      

  4.   

    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.Web.Util; 
    using System.Web.Mail; 
    /// <summary> 
    ///SendMail 的摘要说明 
    /// </summary> public class SendMail 

    public SendMail() 

      // 
      //TODO: 在此处添加构造函数逻辑 
      // 

        /// <summary> 
        ///SendMail 的摘要说明 
        /// </summary> 
        /// <param name="fromMail">发件人 </param> 
        /// <param name="toMail">收件人 </param> 
        /// <param name="ccMail">抄送人 </param> 
        /// <param name="bccMail">暗送人 </param> 
        /// <param name="subject">主题 </param> 
        /// <param name="body">内容 </param> 
        /// <param name="sendMode">模式 </param> 
        /// <returns>查询结果(bool)是否成功 </returns> 
        public bool WriteAndSendMail(string fromMail, string toMail, string ccMail, string bccMail, string subject, string body, string sendMode) 
        { 
            try 
            { 
                MailMessage myMail = new MailMessage(); 
                myMail.From = "[email protected]";// fromMail;//发件人 
                myMail.To = fromMail;//收件人 
                myMail.Cc = ccMail;//抄送人 
                myMail.Bcc = bccMail;//暗送人 
                myMail.Subject = subject;//主题 
                myMail.Body = body; 
                myMail.BodyFormat = sendMode == "0" ? MailFormat.Text : MailFormat.Html; 
                //附件 
                //string ServerFileName = ""; 
                //if (this.upfile.PostedFile.ContentLength != 0) 
                //{ 
                //    string upFileName = this.upfile.PostedFile.FileName; 
                //    string[] strTemp = upFileName.Split('.'); 
                //    string upFileExp = strTemp[strTemp.Length - 1].ToString(); 
                //    ServerFileName = Server.MapPath(DateTime.Now.ToString("yyyyMMddhhmmss") + "." + upFileExp); 
                //    this.upfile.PostedFile.SaveAs(ServerFileName); 
                //    myMail.Attachments.Add(new MailAttachment(ServerFileName)); 
                //} 
                myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1); 
                myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "sunshijie110"); //发送方邮件帐户 
                myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "****"); //发送方邮件密码 
                SmtpMail.SmtpServer = "smtp.126.com"; 
                SmtpMail.Send(myMail); 
                return true; 
            } 
            catch 
            { 
                return false; 
            } 
        } 
      

  5.   

    昨天我刚刚做过,呵呵,不能的啊,你给他发送的url就是连接到你的修改密码的页面上的,有什么难度的?上面的回复已经可以发邮件了,你只要邮件就可以了,然后在修改密码的页面上判断一下是不是从连接进来的,然后处理修改密码。
      

  6.   

    让邮件的主体以html形式各显不可以了吗?根据不同的要求可以设置不同 的邮件主题....