コード例 #1
0
    //  #region
    private ML_Mail ProcessFormPost()
    {
        // 非空验证
        if (string.IsNullOrEmpty(Request.Form["hdnTxtSendTo"].ToString()))
        {
            Response.Write("<script language=javascript>alert('请选择收件人," + Request.Form["hdnTxtSendTo"].ToString() + "!');history.go(-1);</script>");
            Response.End();
        }

        // 处理表单传递参数
        ML_Mail mailbody = new ML_Mail();

        mailbody.MailType = 1; //邮箱类型   1:内部邮件
        mailbody.ReceiverStr = Request.Form["hdnTxtSendTo"].ToString();
        // Response.Write(mailbody.ReceiverStr);

        mailbody.Sender = (string)Session["UserName"];
        mailbody.Receiver = "";
        mailbody.Subject = (txtSubject.Text == "") ? "无主题" : txtSubject.Text;
        mailbody.Content = ckedit_content.Text;
        mailbody.CcToAddr = Request.Form["hdnTxtCcTo"].ToString();
        mailbody.BccToAddr = Request.Form["hdnTxtBccTo"].ToString();
        mailbody.SendTags = Int32.Parse(listSendTags.SelectedItem.Value);
        mailbody.IsRead = "N";
        mailbody.IsDelete = "N";
        int size = this.ckedit_content.Text.Length + (ViewState["UploadSize"] == null ? 0 : (int)ViewState["UploadSize"]);
        if ((size / 1024) == 0) size = 1;
        else size = size / 1024;
        mailbody.Size = size;
        mailbody.Type = 0;
        mailbody.ExtPropertys = "";
        mailbody.Importance = Int32.Parse(listImportance.SelectedItem.Value);
        return mailbody;
    }
コード例 #2
0
    protected void btnSendMail_Click(object sender, EventArgs e)
    {
        ML_Mail mailbody = new ML_Mail();
        mailbody = ProcessFormPost();
        ArrayList mails_id = ML_MailBLL.MailSend(mailbody); // 返回已经发送的邮件ID列表(包括抄送和密抄)

        List<int> receiverList = new List<int>();

        ArrayList upattlist = (ArrayList)Session["upattlist"];

        #region 将附件文件读取到字节组中
        ArrayList upattbuff = new ArrayList(upattlist.Count);
        for (int i = 0; i < upattlist.Count; i++)
        {
            byte[] buff = null;
            ML_AttachFile att = (ML_AttachFile)upattlist[i];
            string path = att.Visualpath;
            if (path == "")
            {
                //转发的附件
                buff = new ML_AttachFileBLL(att.GUID).GetData();
            }
            else
            {
                if (path.StartsWith("~")) path = Server.MapPath(path);
                FileStream stream = new FileStream(path, FileMode.Open);
                buff = new byte[stream.Length];
                stream.Read(buff, 0, buff.Length);
                stream.Close();

                att.Visualpath = "";
                File.Delete(path);
            }
            upattbuff.Add(buff);
        }

        if (ViewState["SavePath"] != null)
        {
            string path = (string)ViewState["SavePath"];
            path = path.Substring(0, path.LastIndexOf("/"));
            Directory.Delete(path, true);
            ViewState["SavePath"] = null;
        }
        #endregion

        ML_AttachFileBLL bll = new ML_AttachFileBLL();
        for (int i = 0; i < upattlist.Count; i++)
        {
            ML_AttachFile att = (ML_AttachFile)upattlist[i];
            foreach (int mailID in mails_id)
            {
                ML_AttachFileBLL attbll = new ML_AttachFileBLL();
                attbll.Model = att;
                attbll.Model.Mailid = mailID;

                attbll.Add((byte[])upattbuff[i]);
            }
        }

        if (this.cbRemind.Checked == true)
        {
            receiverList = ProcessSM();
        }
        Response.Redirect("index.aspx");
    }