首页 > 开发 > 综合 > 正文

邮件发送测试。Codebehind

2024-07-21 02:24:38
字体:
来源:转载
供稿:网友
using system;
using system.web;
using system.web.ui;
using system.web.ui.webcontrols;
using blood.com.classlib;

namespace test
{
    /// <summary>
    /// 邮件发送例子
    /// </summary>
    public class sendmailsample : system.web.ui.page
    {
        protected system.web.ui.webcontrols.datagrid datagrid1;
        protected system.web.ui.webcontrols.dropdownlist ddlpriority;
        protected system.web.ui.webcontrols.dropdownlist ddlhtml;
        protected system.web.ui.webcontrols.textbox txtsmtphost;
        protected system.web.ui.webcontrols.textbox txtport;
        protected system.web.ui.webcontrols.textbox txtfrom;
        protected system.web.ui.webcontrols.textbox txtfromname;
        protected system.web.ui.webcontrols.textbox txtto;
        protected system.web.ui.webcontrols.textbox txttoname;
        protected system.web.ui.webcontrols.textbox txtsubject;
        protected system.web.ui.webcontrols.textbox txtmessage;
        protected system.web.ui.webcontrols.regularexpressionvalidator revport;
        protected system.web.ui.webcontrols.requiredfieldvalidator rfvsmtphost;
        protected system.web.ui.webcontrols.requiredfieldvalidator rfvport;
        protected system.web.ui.webcontrols.requiredfieldvalidator rfvfrom;
        protected system.web.ui.webcontrols.requiredfieldvalidator rfvto;
        protected system.web.ui.webcontrols.requiredfieldvalidator rfvsubject;
        protected system.web.ui.webcontrols.requiredfieldvalidator rfvmessage;
        protected system.web.ui.webcontrols.button btnsendmail;
        protected system.web.ui.webcontrols.label lblmessage;
        protected system.web.ui.webcontrols.regularexpressionvalidator revfrom;
        protected system.web.ui.webcontrols.regularexpressionvalidator revto;
        protected system.web.ui.webcontrols.panel pelmessage;
    
        private void page_load(object sender, system.eventargs e)
        {
        }

        #region web form designer generated code
        override protected void oninit(eventargs e)
        {
            //
            // codegen: this call is required by the asp.net web form designer.
            //
            initializecomponent();
            base.oninit(e);
        }
        
        /// <summary>
        /// required method for designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void initializecomponent()
        {    
            this.btnsendmail.click += new system.eventhandler(this.btnsendmail_click);
            this.load += new system.eventhandler(this.page_load);

        }
        #endregion

        private void btnsendmail_click(object sender, system.eventargs e)
        {
            if(ispostback)
            {
                smtpmail clsmail = new smtpmail();
                string strsmtphost = txtsmtphost.text;
                int intport = int32.parse(txtport.text);
                string strfrom = txtfrom.text;
                string strfromname = txtfromname.text;
                string strto = txtto.text;
                string strtoname = txttoname.text;
                smtpmail.prioritys priority = smtpmail.prioritys.normal;
                bool bolhtml;
                string strsubject = txtsubject.text;
                string strmessage = txtmessage.text;
                if(ddlpriority.selecteditem.text == "默认")
                {
                    priority = smtpmail.prioritys.normal;
                }
                else if(ddlpriority.selecteditem.text == "高")
                {
                    priority = smtpmail.prioritys.high;
                }
                else if(ddlpriority.selecteditem.text == "低")
                {
                    priority = smtpmail.prioritys.low;
                }
                if(ddlhtml.selecteditem.text == "是")
                {
                    bolhtml = true;
                }
                else
                {
                    bolhtml = false;
                }
                clsmail.sendmail(strsmtphost,intport,strfrom,strfromname,strto,strtoname,priority,bolhtml,"",strsubject,strmessage);
                if(clsmail.errormessage !="")
                {
                    pelmessage.visible = true;
                    lblmessage.text = clsmail.errormessage;
                    lblmessage.forecolor = system.drawing.color.red;
                }
                else
                {
                    pelmessage.visible = true;
                    lblmessage.text = "邮件发送成功";
                    lblmessage.forecolor = system.drawing.color.blue;
                }
            }
        }
    }
}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表