示例#1
0
        protected void BtnSend_Click(object sender, EventArgs e)
        {
            var key     = string.Format(m_SessionKey_MailMessage, MessageID);
            var message = Session[key] as MailPageMessage;

            if (message != null)
            {
                //如果是基于模板的方式的邮件,根据原始的MailMessage和现在UI上的输入进行比较,
                //如果有改变,则不再使用模板发送, 反之则使用模板方式发送;
                if (!string.IsNullOrWhiteSpace(message.MailMessage.TemplateID))
                {
                    var b = AreSendByTemplate(message.MailPageSetting);
                    if (!b)
                    {
                        message.MailMessage.TemplateID = null;
                    }
                    else
                    {
                        message.MailMessage.TemplateID = this.ddlTemplates.SelectedValue;
                    }
                }

                message.MailMessage.From    = txtFrom.Text.Trim().TrimEnd(';');
                message.MailMessage.To      = txtTo.Text.Trim().TrimEnd(';');
                message.MailMessage.Subject = txtSubject.Text.Trim();

                if (message.MailPageSetting.IsAllowChangeMailBody)
                {
                    message.MailMessage.Body = txtBody.Text.Trim();
                }

                if (message.MailPageSetting.IsAllowCC)
                {
                    message.MailMessage.CC = txtCC.Text.Trim().TrimEnd(';');
                }
                else
                {
                    message.MailMessage.CC = null;
                }
                if (message.MailPageSetting.IsAllowBCC)
                {
                    message.MailMessage.BCC = txtBCC.Text.Trim().TrimEnd(';');
                }
                else
                {
                    message.MailMessage.BCC = null;
                }

                if (message.MailPageSetting.IsAllowAttachment)
                {
                    message.MailMessage.Attachments = AttachmentHelper.GetFileAttachment(Request.Files);
                }

                try
                {
                    MailBiz.SendBusinessMail(message.MailMessage);
                    ScriptExecute("jAlert('" + this.GetLocalResourceObject("Info_SendSuccessfully") + "', '" + this.GetLocalResourceObject("Info_Alert_Title") + "', function() { closeWindow(); });");

                    this.BtnSend.Enabled = false;
                }
                catch (Exception ex)
                {
                    ScriptExecute("jAlert('" + ex.Message + "','" + this.GetLocalResourceObject("Info_Alert_Title") + "');");
                }
            }
        }