主页 > 编程资料 > C# >
发布时间:2015-09-26 作者:网络 阅读:174次

后台代码:

//-------------------------------------------------------------------------------------------------------

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Mail;
using System.IO;

namespace SendEmailModule
...{
    /**////


    /// sendMailResume 的摘要说明。
    ///

    public class sendMailResume : System.Web.UI.Page
    ...{
        protected System.Web.UI.WebControls.Panel panelMessage;
        protected System.Web.UI.WebControls.Panel panelMain;
        protected System.Web.UI.WebControls.RequiredFieldValidator rfvEmail;
        protected System.Web.UI.WebControls.TextBox txtYourEmail;
        protected System.Web.UI.WebControls.TextBox txtMessage;
        protected System.Web.UI.WebControls.Button btnSubmit;
        protected System.Web.UI.WebControls.RegularExpressionValidator RevEmail;
        protected System.Web.UI.WebControls.Label lblAlert;
        protected System.Web.UI.WebControls.Button btnUploadOk;
        protected System.Web.UI.HtmlControls.HtmlInputFile fileUpload;
        protected System.Web.UI.WebControls.Label lblUploadFileds;
        protected System.Web.UI.WebControls.Panel PanelError;
   
        private void Page_Load(object sender, System.EventArgs e)
        ...{
            // First on Load
            if(!this.IsPostBack)           
            ...{               
                this.theArrayFile = new ArrayList();               
            }
        }

        private void btnUploadOk_Click(object sender, System.EventArgs e)
        ...{
            string fullPath = this.fileUpload.PostedFile.FileName;
            if(fullPath == "")
                return;           
            string Filepostfix = fullPath.Substring(fullPath.LastIndexOf(".") + 1).ToLower();
            if(Filepostfix == "doc" || Filepostfix == "pdf")
                saveResumeFile(fullPath);
            else
                return;

            string temp = null;
            for(int i=0; i            ...{
                string[] str = this.theArrayFile[i].ToString().Split('#');
                temp += string.Format(@"{0} | ",str[0]);
            }
            this.lblUploadFileds.Text= temp;
        }

        private void btnSubmit_Click(object sender, System.EventArgs e)
        ...{
                sendEmail();
        }   

        Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
        override protected void OnInit(EventArgs e)
        ...{
            //
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            //
            InitializeComponent();
            base.OnInit(e);
        }
       
        /**////


        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        ///

        private void InitializeComponent()
        ...{   
            this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
            this.btnUploadOk.Click += new System.EventHandler(this.btnUploadOk_Click);
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion

 

        /**////


        /// save Resume File
        ///

        /// clinet file path
        private void saveResumeFile(string clientFile)
        ...{
            string fullPath = clientFile;        //this.fileUpload.PostedFile.FileName;
            string fileName = fullPath.Substring(fullPath.LastIndexOf("\") + 1);           
            string currentDayTime = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace(@":","");
            string fileSavePath = string.Format(@"{0}{1}_{2}",Server.MapPath("theResumeFile"),currentDayTime,fileName);
           
            try
            ...{
                this.fileUpload.PostedFile.SaveAs(fileSavePath);
                string fileNameAndPath = string.Format("{0}#{1}",fileName,fileSavePath);
                theArrayFile.Add(fileNameAndPath);
            }
            catch(System.Exception sendE)
            ...{
                Response.Write(sendE.ToString());
            }

           
        }

       
        /**////


        /// send Email
        ///

        public void sendEmail()
        ...{
            try
            ...{
                string selSubject     = "Resume (posted from SSBG website)";       
                string txtYourEmail     = this.txtYourEmail.Text.Trim();   
                string txtMessage     = this.txtMessage.Text.Trim();

                string strFromMan     = txtYourEmail;
                //string strToMan         =     "dev2@ssbg.com.cn";        //"Resume@ssbg.com.cn";
                string strToMan  = System.Configuration.ConfigurationSettings.AppSettings["EmailTo"].ToString();
                MailMessage Mail=new MailMessage();

                Mail.From =strFromMan;
                Mail.To = strToMan;

                Mail.Subject = string.Format("{0}",selSubject);

                string theShow ="";
                theShow += "

";
                theShow += string.Format("
",selSubject); 
                theShow += string.Format("
","Message:",txtMessage);
                theShow += "
{0}
{0}{1} 
";   
               
                Mail.Body ="" + theShow + "";
                Mail.BodyFormat=MailFormat.Html;
                try
                ...{// Add file
                    for(int i=0; i< this.theArrayFile.Count; i++)
                    ...{
                        string[] str = this.theArrayFile[i].ToString().Split('#');
                        MailAttachment attachment = new MailAttachment(str[1]);
                        Mail.Attachments.Add(attachment);
                    }
                }
                catch(System.Exception ef)
                ...{
                    Response.Write(ef.ToString());
                }
                   
                Mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
                Mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername","Sendviaweb@ssbg.com.cn");//这里填写你邮箱的用户名
                Mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword","ssbgroup");        //你邮箱的密码

                SmtpMail.SmtpServer= "mail.ssbg.com.cn";
                SmtpMail.Send(Mail);
                this.panelMessage.Visible = true;
                this.panelMain.Visible = false;
                this.PanelError.Visible = false;

                this.DeleteFiles();
            }
            catch
            ...{
                this.PanelError.Visible = true;
                this.panelMain.Visible = false;
                this.panelMessage.Visible = false;
                   
            }
        }

        private void DeleteFiles()
        ...{
            FileInfo[]   TheGetFiles = OperationClass.GetFiles(Server.MapPath("theResumeFile"));
            foreach(FileInfo f in TheGetFiles)
            ...{
                try
                ...{
                    f.Delete();
                }
                catch
                ...{
                    continue;
                }
            }
        }

//--------------
        private ArrayList theArrayFile
        ...{
            get...{return Session["ArrayFile"] as ArrayList;}
            set...{Session["ArrayFile"] = value;}
        }


    }


    public class OperationClass
    ...{
        /**////  

  
        ///   get all files  
        ///  
  
        ///   current dir path  
        ///     
        public static   FileInfo[]   GetFiles(string fullPath)  
        ...{  
            DirectoryInfo   curDir   =   new   DirectoryInfo(fullPath);  
            FileInfo[]   fileInfo   =   curDir.GetFiles();  
            return   fileInfo;  
        }
    }
}

//***************************************************************************************

前台代码:

<%@ Page language="c#" Codebehind="sendMailResume.aspx.cs" AutoEventWireup="false" Inherits="SendEmailModule.sendMailResume" %>


   
        === Send your resume ===
       
       
       
       
       
   
   
       


           
               

                   

                       
                           
                               
  
     
                                               
                                                   
                                               
                                           

                                                       
                                                           
                                                               
                                                           
                                                           
                                                               
                                                               
                                                               
                                                           
                                                           
                                                               
                                                               
                                                               
                                                           
                                                           
                                                               
                                                               
                                                               
                                                               
                                                           
                                                           
                                                               
                                                               
                                                               
                                                               
                                                           
                                                           
                                                               
                                                               
                                                               
                                                               
                                                           
                                                           
                                                               
                                                               
                                                               
                                                               
                                                           
                                                           
                                                               
                                                               
                                                               
                                                           
                                                           
                                                               
                                                               
                                                               
                                                           
                                                           
                                                               
                                                               
                                                               
                                                               
                                                               
                                                           
                                                           
                                                               
                                                               
                                                               
                                                               
                                                               
                                                           
                                                       

                                                                   

                                                                       

Send your Resume


                                                                   

                                                               
      

                                                                   

                                                               

                                                                   
Fields marked by an sterlsk(*)
                                                                        are required.
                                                                   

                                                               

                                                                   

                                                               

                                                                   
Your email:

                                                               

                                                                    *
                                                                    input your email!
                                                                    input your email!

                                                                   
Upload Resume:

                                                               
 
                                                                    *
                                                                        (.doc | .pdf)

                                                                   

                                                                   

                                                               

                  &nbs, p;                                                
Message:

                                                               

                                                                   

                                                                   

                                                               
Maximum 2000 characters
 
                                                               

                                                                     
 

                                                   

                                                                                            bgColor="#5887a5" border="0">
                                               
                                                   
                                                       
                                                   
                                                   
                                                       
                           
                           
                               
                           
                       
EMAIL SENT:

                                                           
                                                               
                                                                   
                                                               
                                                               
                                                                   
                                                               
                                                               
                                                                   
                                                               
                                                               
                                                                   
                                                               
                                                               
                                                                   
                                                               
                                                           
The mail
                                                                        already send to the SSBG mailbox, thank you!
             
                                                                        Sincerely        
                                                                   
SSBG - IT
                                                                        Solutions  
                                                                   
  
                                                                       

                                                                   
 

               

                                    align="center" border="0">
                   
                       
                   
                   
                       
                   
                   
                       
                   
               
Message :
The network malfunction, the
                            Email transmission defeat, please transmit, thanks!
                       
 

           

   

 


 

<> <>
关键字词: