发邮件、带附件。利用属性升级变量轻松使用Session

80酷酷网    80kuku.com

  session|变量|发邮件

后台代码:

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

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
...{
    /**//// <summary>
    /// sendMailResume 的摘要说明。
    /// </summary>
    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<theArrayFile.Count; 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);
        }
       
        /**//// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        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

 

        /**//// <summary>
        /// save Resume File
        /// </summary>
        /// <param name="clientFile">clinet file path</param>
        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());
            }

           
        }

       
        /**//// <summary>
        /// send Email
        /// </summary>
        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         =     "dev2ssbg.com.cn";        //"Resumessbg.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 += "<table align=center width='80%'   cellpadding='0' cellspacing='0' bordercolorlight='#6699ff' bordercolordark='#6699ff' collapse;margin: 0px;padding: 0px;' border = '1'>";
                theShow += string.Format("<tr><td colspan ='2' align='center'><b>{0}</b></td><tr>",selSubject); 
                theShow += string.Format("<TR><TD align='Left' nowrap width='20%'>{0}</TD><TD>{1} </TD></TR>","Message:",txtMessage);
                theShow += "</TABLE>";   
               
                Mail.Body ="<html><head><link rel='stylesheet' name="vs_defaultClientScript">
        <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
        <LINK href="ContactUs_emx_nav_left.css" type="text/css" rel="stylesheet">
    </HEAD>
    <body bgColor="#5887a5">
        <form id="Form1" method="post" runat="server">
            <FONT face="宋体">
                <DIV align="center">
                    <DIV align="center">
                        <TABLE id="Table2" cellSpacing="0" cellPadding="0" width="100%" border="0">
                            <TR>
                                <TD 177px" vAlign="top"><FONT face="宋体"><asp:panel id="panelMain" Runat="server">  
      <TABLE id="Table6" cellSpacing="1" cellPadding="1" width="100%" align="center" border="0">
                                                <TR>
                                                    <TD>
                                                        <TABLE id="Table5" cellSpacing="1" cellPadding="1" align="center" bgColor="#ffffff" border="0">
                                                            <TR>
                                                                <TD 21px" align="right" colSpan="5"><FONT face="宋体"></FONT></TD>
                                                            </TR>
                                                            <TR>
                                                                <TD 21px" align="right"><FONT face="宋体"></FONT></TD>
                                                                <TD align="right" colSpan="3">
                                                                    <DIV align="center">
                                                                        <H2><STRONG 20px">Send your Resume</STRONG></H2>
                                                                    </DIV>
                                                                </TD>
                                                                <TD align="right"><FONT face="宋体">      </FONT></TD>
                                                            </TR>
                                                            <TR>
                                                                <TD 21px" align="right" colSpan="2">
                                                                    <DIV align="left"></DIV>
                                                                </TD>
                                                                <TD align="right" colSpan="2">
                                                                    <DIV align="left">Fields marked by an sterlsk(<SPAN #ff0066">*</SPAN>)
                                                                        are required.
                                                                    </DIV>
                                                                </TD>
                                                                <TD align="right"></TD>
                                                            </TR>
                                                            <TR>
                                                                <TD class="number" 21px; HEIGHT: 19px" noWrap>
                                                                    <DIV align="right"></DIV>
                                                                </TD>
                                                                <TD class="number" 19px" noWrap>
                                                                    <DIV align="right"><STRONG>Your email:</STRONG></DIV>
                                                                </TD>
                                                                <TD 19px" colSpan="2">
                                                                    <asp:TextBox id="txtYourEmail" runat="server" Width="232px"></asp:TextBox><SPAN #ff0066">*</SPAN>
                                                                    <asp:RequiredFieldValidator id="rfvEmail" runat="server" ErrorMessage="*" ControlToValidate="txtYourEmail" Display="Dynamic">input your email!</asp:RequiredFieldValidator>
                                                                    <asp:RegularExpressionValidator id="RevEmail" runat="server" ErrorMessage="*" ControlToValidate="txtYourEmail" ValidationExpression="w+([-+.]w+)*w+([-.]w+)*.w+([-.]w+)*">input your email!</asp:RegularExpressionValidator></TD>
                                                                <TD 19px"></TD>
                                                            </TR>
                                                            <TR>
                                                                <TD class="number" 21px" vAlign="top" noWrap></TD>
                                                                <TD class="number" vAlign="top" noWrap>
                                                                    <DIV align="right"><STRONG>Upload Resume:</STRONG></DIV>
                                                                </TD>
                                                                <TD colSpan="2"><INPUT id="fileUpload" type="file" name="File2" runat="server"> 
                                                                    <asp:Button id="btnUploadOk" runat="server" Width="66px" Height="22px" Text="Upload"></asp:Button><SPAN #ff0066">*
                                                                        <asp:Label id="lblAlert" runat="server" Width="166px" ForeColor="#404040">(.doc | .pdf)</asp:Label></SPAN></TD>
                                                                <TD></TD>
                                                            </TR>
                                                            <TR>
                                                                <TD class="number" 21px" vAlign="top" noWrap></TD>
                                                                <TD class="number" vAlign="top" noWrap></TD>
                                                                <TD colSpan="2">
                                                                    <asp:Label id="lblUploadFileds" runat="server" Width="100%" Height="8px"></asp:Label></TD>
                                                                <TD></TD>
                                                            </TR>
                                                            <TR>
                                                                <TD class="number" 21px" vAlign="top" noWrap>
                                                                    <DIV align="right"><FONT face="宋体"></FONT></DIV>
                                                                </TD>
                                                                <TD class="number" vAlign="top" noWrap>
                  &nbs, p;                                                 <DIV align="right"><STRONG>Message:</STRONG></DIV>
                                                                </TD>
                                                                <TD colSpan="2">
                                                                    <asp:TextBox id="txtMessage" runat="server" Width="507px" TextMode="MultiLine" Height="113px"></asp:TextBox></TD>
                                                                <TD></TD>
                                                            </TR>
                                                            <TR>
                                                                <TD class="number" 21px; HEIGHT: 10px" noWrap colSpan="2">
                                                                    <DIV align="right"></DIV>
                                                                </TD>
                                                                <TD 10px" vAlign="top" colSpan="2">Maximum 2000 characters</TD>
                                                                <TD 12px" vAlign="top"></TD>
                                                            </TR>
                                                            <TR>
                                                                <TD 21px" colSpan="2"></TD>
                                                                <TD colSpan="2"></TD>
                                                                <TD></TD>
                                                            </TR>
                                                            <TR>
                                                                <TD 21px" vAlign="top" align="center"><FONT face="宋体"></FONT></TD>
                                                                <TD vAlign="top" align="center"> 
                                                                </TD>
                                                                <TD vAlign="top" align="left">
                                                                    <asp:Button id="btnSubmit" runat="server" Text="Submit"></asp:Button> </TD>
                                                                <TD vAlign="top" align="center"> </TD>
                                                                <TD vAlign="top" align="center"></TD>
                                                            </TR>
                                                            <TR>
                                                                <TD 21px" vAlign="top" align="center"></TD>
                                                                <TD vAlign="top" align="center"></TD>
                                                                <TD vAlign="top" align="left"></TD>
                                                                <TD vAlign="top" align="center"></TD>
                                                                <TD vAlign="top" align="center"></TD>
                                                            </TR>
                                                        </TABLE>
                                                    </TD>
                                                </TR>
                                            </TABLE></asp:panel><asp:panel id="panelMessage" runat="server" BackColor="#5887A5" Visible="False">
                                            <TABLE id="Table1" 498px; HEIGHT: 75px" cellSpacing="1" cellPadding="1" align="center"
                                                bgColor="#5887a5" border="0">
                                                <TBODY>
                                                    <TR #cccccc">
                                                        <TD 12px" bgColor="#cccccc" colSpan="2"><FONT face="宋体">EMAIL SENT:</FONT></TD>
                                                    </TR>
                                                    <TR>
                                                        <TD 72px" vAlign="top" colSpan="2">
                                                            <TABLE id="Table4" cellSpacing="0" cellPadding="0" width="100%" border="0">
                                                                <TR black">
                                                                    <TD #ffffff; HEIGHT: 26px" bgColor="#5887a5">The mail
                                                                        already send to the SSBG mailbox, thank you!</TD>
                                                                </TR>
                                                                <TR>
                                                                    <TD 18px" bgColor="#5887a5"><FONT face="宋体"></FONT></TD>
                                                                </TR>
                                                                <TR>
                                                                    <TD #ffffff; HEIGHT: 17px" align="right" bgColor="#5887a5">             
                                                                        Sincerely        
                                                                    </TD>
                                                                </TR>
                                                                <TR>
                                                                    <TD #ffffff; HEIGHT: 17px" align="right" bgColor="#5887a5">SSBG - IT
                                                                        Solutions  
                                                                    </TD>
                                                                </TR>
                                                                <TR>
                                                                    <TD align="right" bgColor="#5887a5"><A href="#">  
                                                                        </A>
                                                                    </TD>
                                                                </TR>
                                                            </TABLE></FONT></TD>
                            </TR>
                            <TR #cccccc">
                                <TD colSpan="2"><FONT face="宋体"> </FONT></TD>
                            </TR>
                        </TABLE>
                </asp:panel></FONT><asp:panel id="PanelError" runat="server" BackColor="#5887A5" Visible="False">
                <TABLE id="Table3" 498px; HEIGHT: 75px" cellSpacing="1" cellPadding="1" width="498"
                    align="center" border="0">
                    <TR #99ccff">
                        <TD #cccccc" colSpan="2"><FONT face="宋体">Message :</FONT></TD>
                    </TR>
                    <TR #ffffff">
                        <TD #ffffff; HEIGHT: 20px" colSpan="2">The network malfunction, the
                            Email transmission defeat, please transmit, thanks!
                        </TD>
                    </TR>
                    <TR #cccccc">
                        <TD colSpan="2"><FONT face="宋体"> </FONT></TD>
                    </TR>
                </TABLE>
            </asp:panel></TD></TR></TBODY></TABLE></DIV></DIV></FONT></form>
    </body>
</HTML>

 

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: