Ejemplo n.º 1
0
        /// <summary>
        /// 从邮件中获取新的更新信息
        /// </summary>
        protected void GetEmailUpdateInfo()
        {
            //获取邮件配置信息
            FrameConfig FC = new FrameConfig();
            string ConfigStr = FC.GetDetail("HostMail").ConfigValue;
            FrameCommon FComm = new FrameCommon();
            string UserName = FComm.FindValueFromStr(ConfigStr, "UserName="******"Password="******"POP3Host=").Trim();
            int Pop3Port = Convert.ToInt32(FComm.FindValueFromStr(ConfigStr, "POP3Port=").Trim());
            bool IsSSL = FComm.FindValueFromStr(ConfigStr, "EnableSsl=").Trim() == "1" ? true : false;
            //连接邮件服务器
            using (POP3_Client MyClient = new POP3_Client())
            {
                MyClient.Connect(Pop3Host, Pop3Port, IsSSL);
                MyClient.Authenticate(UserName, Password, false);
                string SystemGuid = FComm.GetSystemGuid();
                for (int i = 0; i < MyClient.Messages.Count; i++)
                {
                    POP3_ClientMessage mail = MyClient.Messages[i];
                    Mime m = Mime.Parse(mail.MessageToByte());
                    if (m.Attachments.Length > 0 && m.MainEntity.Subject.ToLower().IndexOf(SystemGuid.ToLower()) > -1) //如果有附件,且为该系统的标识
                    {
                        string UpdateSubject = m.MainEntity.Subject;
                        DateTime UpdateTime = m.MainEntity.Date;
                        string UpdateContent = m.BodyText;
                        int FileCount = m.Attachments.Length;
                        string UpdateGuid = System.Guid.NewGuid().ToString();
                        string FilePath = "/UpdateBackUp/" + UpdateTime.ToString("yyyyMMdd") + "-" + new System.Random().Next(1000, 9999).ToString() + "/"; //生成路径
                        string FilenameList = "";
                        //将基本信息存入数据库

                        foreach (MimeEntity entry in m.Attachments)
                        {

                            string fileName = entry.ContentDisposition_FileName; //获取文件名称
                            if (fileName != null && fileName.Trim() != "")  //有些文件取不到,如txt
                            {
                                FilenameList = FilenameList + fileName + ";";
                                string DirPath = Server.MapPath(FilePath);
                                System.IO.Directory.CreateDirectory(DirPath);
                                string FileURL = DirPath + fileName;
                                FileInfo fi = new FileInfo(FileURL);
                                byte[] data = entry.Data;
                                FileStream pFileStream = null;
                                pFileStream = new FileStream(FileURL, FileMode.Create);
                                pFileStream.Write(data, 0, data.Length);
                                pFileStream.Close();
                            }
                        }
                        mail.MarkForDeletion();
                        new FrameUpdate().InsertUpdate(UpdateGuid, UpdateTime, UpdateSubject, UpdateContent, FileCount, FilenameList, FilePath);
                    }

                }
                MyClient.Disconnect();
            }

            this.Refresh();
        }
Ejemplo n.º 2
0
        protected void GetInfo()
        {
            FrameConfig FC=new FrameConfig();
            txtServerMail.Text = FC.GetDetail("ServerMail").ConfigValue.Trim();
            txtTitle.Text = FC.GetDetail("ErrorReportMailTitle").ConfigValue.Trim();
            txtMailBody.Text = FC.GetDetail("ErrorReportMailBody").ConfigValue;

            string ConfigStr = FC.GetDetail("HostMail").ConfigValue;
            FrameCommon FComm = new FrameCommon();
            txtSenderName.Text = FComm.FindValueFromStr(ConfigStr, "FromName=").Trim();
            txtSenderEmail.Text = FComm.FindValueFromStr(ConfigStr, "UserName="******"Password="******"Port=").Trim();
            txtSMTP.Text = FComm.FindValueFromStr(ConfigStr, "Host=").Trim();
            chbSSL.Checked = FComm.FindValueFromStr(ConfigStr, "EnableSsl=").Trim() == "1" ? true : false;
            chbAsy.Checked = FComm.FindValueFromStr(ConfigStr, "SendAsync=").Trim() == "1" ? true : false;

            txtPop3Host.Text = FComm.FindValueFromStr(ConfigStr, "POP3Host=").Trim();
            txtPop3Port.Text = FComm.FindValueFromStr(ConfigStr, "POP3Port=").Trim();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 邮件通知这些错误
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btnEmail_Click(object sender, EventArgs e)
        {
            //获取邮件配置信息
            FrameConfig FC = new FrameConfig();
            string ServerEmail = FC.GetDetail("ServerMail").ConfigValue;  //接收邮件地址
            string HostEmail = FC.GetDetail("HostMail").ConfigValue; //发送方邮件配置信息
            if (ServerEmail == "" || HostEmail == "")
            {
                ShowJsMessage("您没有配置邮件信息(ServerMail和HostMail),不能发送邮件!");
                return;
            }

            bool HasMailed = false;
            string AttachFile = "";
            string ReportGuid = "";
            for (int i = 0; i < grdList.Items.Count; i++)
            {
                CheckBox chkSingle = (CheckBox)grdList.Items[i].FindControl("chkAdd");
                if (chkSingle.Checked)
                {
                    Label lb = (Label)grdList.Items[i].FindControl("lbTime");
                    DateTime dt = Convert.ToDateTime(lb.Text.Trim());
                    AttachFile += Server.MapPath("~/Error/" + dt.Year.ToString() + "/" + dt.Month.ToString() + "/" + dt.Day.ToString() + ".txt") + ";";

                    ReportGuid += Convert.ToString(grdList.DataKeys[i]) + ";";
                    HasMailed = true;
                }
            }
            if (!HasMailed)
            {
                ShowJsMessage("您没有选择要发送邮件的错误报告!");
            }
            else
            {
                try
                {
                    string MailTitle = FC.GetDetail("ErrorReportMailTitle").ConfigValue;
                    string mailBody = FC.GetDetail("ErrorReportMailBody").ConfigValue.Replace(" ", "&nbsp;").Replace("\r\n", "<br />");
                    SendMail SM = new SendMail(HostEmail, ServerEmail, MailTitle, mailBody, AttachFile);
                    bool isok = SM.Send();
                    if (isok)
                        ShowJsMessage("错误报告发送成功!");
                    else
                        ShowJsMessage("错误报告发送异常,请检查!");

                }
                catch (Exception a)
                {
                    ShowJsMessage("错误信息:" + a.Message);
                    return;
                }
                 //设置已发送邮件标识,确保数据库邮件状态与实际邮件发送一致
                string[] ReportGuidlist = ReportGuid.Split(';');
                for (int i = 0; i < ReportGuidlist.Length; i++)
                {
                    if (ReportGuidlist[i].Trim() != "")
                    {
                        new FrameErrorLog().UpdateEmailed(ReportGuidlist[i].Trim());
                    }
                }
            }
            this.BindGrid();
        }