public ActionResult SetMailTemplate(MailTemplateSetModels model)
        {
            model.MailContent = HttpUtility.UrlDecode(model.MailContent);
            bool Result = MemberShipSettingDAO.SetMailTemplateItems(model);

            return(Json(Result ? "success" : "fail"));
        }
示例#2
0
        public static bool SetMailTemplateItems(MailTemplateSetModels item)
        {
            SQLData.Database db = new SQLData.Database(WebInfo.Conn);
            item.AttFiles = item.AttFiles == null ? "" : item.AttFiles;
            SQLData.TableObject tableObj = db.GetTableObject("MailTemplateSet");
            tableObj.GetDataFromObject(item);
            DateTime now   = DateTime.Now;
            string   sql   = $"SELECT * FROM MailTemplateSet WHERE  TemplateName='{ item.TemplateName.Replace("'", "")}' ";
            bool     isNew = db.GetFirstValue(sql) == null;

            if (isNew)
            {
                tableObj["Creator"]    = Areas.Backend.Models.DataAccess.MemberDAO.SysCurrent.Id;
                tableObj["CreateTime"] = now;
                tableObj["Modifier"]   = WorkV3.Areas.Backend.Models.DataAccess.MemberDAO.SysCurrent.Id;
                tableObj["ModifyTime"] = now;
                tableObj.Insert();
            }
            else
            {
                tableObj.Remove("TemplateName");
                tableObj.Remove("Creator");
                tableObj.Remove("CreateTime");
                tableObj["Modifier"]   = WorkV3.Areas.Backend.Models.DataAccess.MemberDAO.SysCurrent.Id;
                tableObj["ModifyTime"] = now;
                tableObj.Update(item.TemplateName);
            }
            return(true);
        }
        public ActionResult GetMailTemplate(string TemplateName)
        {
            MailTemplateSetModels model = MemberShipSettingDAO.GetMailTemplateItems(TemplateName);

            // model.StatementContent = HttpUtility.UrlEncode(model.StatementContent);

            return(Json(model, JsonRequestBehavior.AllowGet));
        }
        public ActionResult TryToMail(long SiteID, long MenuID, string TemplateName)
        {
            ViewBag.SiteID       = SiteID;
            ViewBag.MenuID       = MenuID;
            ViewBag.TemplateName = TemplateName;
            MailTemplateSetModels model = MemberShipSettingDAO.GetMailTemplateItems(TemplateName);

            return(View(model));
        }
        public ActionResult DeleteFile(string TemplateName, int fileIndex)
        {
            MailTemplateSetModels model = MemberShipSettingDAO.GetMailTemplateItems(TemplateName);
            List <WorkV3.Models.ResourceFilesModels> fileList = Newtonsoft.Json.JsonConvert.DeserializeObject <List <WorkV3.Models.ResourceFilesModels> >(model.AttFiles);

            if (fileIndex < fileList.Count)
            {
                fileList.RemoveAt(fileIndex);
            }
            model.AttFiles = Newtonsoft.Json.JsonConvert.SerializeObject(fileList);
            bool Result = MemberShipSettingDAO.SetMailTemplateItems(model);

            return(Json(Result ? "success" : "fail"));
        }
        public ActionResult SentTryMail(long SiteID, long MenuID, string TemplateName, string MailToList)
        {
            ViewBag.SiteID       = SiteID;
            ViewBag.MenuID       = MenuID;
            ViewBag.TemplateName = TemplateName;
            string message              = "";
            string SitesTitle           = WorkV3.Models.DataAccess.SitesDAO.GetInfo(SiteID).Title;
            MailTemplateSetModels model = MemberShipSettingDAO.GetMailTemplateItems(TemplateName);

            if (model == null)
            {
                return(Json(new { result = "fail", message = "範本取得失敗" }));
            }
            if (!string.IsNullOrEmpty(MailToList))
            {
                int    mailCount   = 0;
                string mailSubject = model.MailTitle
                                     .Replace("[WebsiteName]", SitesTitle);//Joe 20190924 改抓網站名稱
                string mailContent = model.MailContent
                                     .Replace("[WebsiteName]", SitesTitle)
                                     .Replace("[SendDate]", DateTime.Now.ToString("yyyy/MM/dd"));
                ArrayList attFileList = new ArrayList();
                if (!string.IsNullOrEmpty(model.AttFiles))
                {
                    string UploadVPath = WorkV3.Golbal.UpdFileInfo.GetUPathByMenuID(SiteID, MenuID);
                    List <WorkV3.Areas.Backend.Models.ResourceFilesModels> fileList = Newtonsoft.Json.JsonConvert.DeserializeObject <List <WorkV3.Areas.Backend.Models.ResourceFilesModels> >(model.AttFiles);
                    foreach (WorkV3.Areas.Backend.Models.ResourceFilesModels f in fileList)
                    {
                        //System.Net.Mail.Attachment attFile = new System.Net.Mail.Attachment(UploadVPath + "/" + f.FileInfo);
                        attFileList.Add(UploadVPath + f.FileInfo);
                    }
                }
                string[] mailTos = MailToList.Split(';');
                foreach (string mailTo in mailTos)
                {
                    try
                    {
                        new System.Net.Mail.MailAddress(mailTo);
                    }
                    catch
                    {
                        message += string.Format("[{0}]需為 E-Mail 格式\n", mailTo);
                        continue;
                    }
                    if (attFileList.Count > 0)
                    {
                        WorkLib.uEMail.SendMailWithFiles(mailTo, "", mailSubject, mailContent, attFileList, model.MailFromAddress, SitesTitle);
                    }
                    else
                    {
                        WorkLib.uEMail.SendEMail(mailTo, "", mailSubject, mailContent, model.MailFromAddress, SitesTitle);
                    }
                    mailCount++;
                }
                message += string.Format("共寄出{0}封測試信件", mailCount.ToString());
                //string VerifyUrl = string.Format("{0}://{1}{2}{3}/w/{4}/Verify?M={5}&K={6}", HttpContext.Current.Request.Url.Scheme,
                //    HttpContext.Current.Request.Url.DnsSafeHost,
                //    HttpContext.Current.Request.Url.Port == 80 ? "" : ":" + HttpContext.Current.Request.Url.Port.ToString(),
                //    HttpContext.Current.Request.ApplicationPath == "/" ? "" : "/" + HttpContext.Current.Request.ApplicationPath.Trim('/'),
                //    WorkLib.GetItem.appSet("DefaultSiteSN").ToString(),
                //    tableObj["ID"].ToString(), item.VerifyCode);
            }
            else
            {
            }
            return(Json(new { result = "success", message = message }));
        }
示例#7
0
        public static MailTemplateSetModels GetMailTemplateItems(string TemplateName)
        {
            string sel_sql = $"SELECT * FROM MailTemplateSet WHERE  TemplateName='{ TemplateName.Replace("'", "")}' ";

            using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(WebInfo.Conn))
            {
                var qResult = conn.Query <MailTemplateSetModels>(sel_sql);
                if (qResult != null && qResult.Count() > 0)
                {
                    MailTemplateSetModels model = qResult.First();
                    model.AttShowFiles = "";
                    if (!string.IsNullOrEmpty(model.AttFiles))
                    {
                        List <ViewModels.MemberShipSetFile>      fileShowList = new List <ViewModels.MemberShipSetFile>();
                        List <WorkV3.Models.ResourceFilesModels> fileList     = Newtonsoft.Json.JsonConvert.DeserializeObject <List <WorkV3.Models.ResourceFilesModels> >(model.AttFiles);
                        foreach (WorkV3.Models.ResourceFilesModels fileModel in fileList)
                        {
                            ViewModels.MemberShipSetFile showFile = new ViewModels.MemberShipSetFile()
                            {
                                FileInfo     = fileModel.FileInfo,
                                FileSize     = fileModel.FileSize.HasValue ? fileModel.FileSize.Value : 0,
                                FileSizeDesc = "0",
                                ShowName     = fileModel.ShowName
                            };
                            showFile.FileSizeDesc = WorkLib.uFiles.SizeToText((long)showFile.FileSize);
                            fileShowList.Add(showFile);
                        }
                        model.AttShowFiles = Newtonsoft.Json.JsonConvert.SerializeObject(fileShowList);
                    }
                    return(model);
                }
                else
                {
                    MailTemplateSetModels item = new MailTemplateSetModels();
                    item.TemplateName = TemplateName;
                    System.Xml.XmlDocument xmldoc = new System.Xml.XmlDocument();
                    xmldoc.Load(HttpContext.Current.Server.MapPath("~/App_Data/mailContent/MailTemplates.xml"));
                    System.Xml.XmlNode templateNode = xmldoc.SelectSingleNode(string.Format("/Mails/Template[@ID='{0}']", TemplateName));

                    item.MailTitle       = templateNode.SelectSingleNode("Subject").InnerXml;
                    item.MailContent     = templateNode.SelectSingleNode("Content").InnerXml;
                    item.MailFromName    = (string)WorkLib.GetItem.appSet("MailSender");
                    item.MailFromAddress = (string)WorkLib.GetItem.appSet("MailFrom");
                    item.AttFiles        = "";
                    SQLData.Database    db       = new SQLData.Database(WebInfo.Conn);
                    SQLData.TableObject tableObj = db.GetTableObject("MailTemplateSet");
                    tableObj.GetDataFromObject(item);
                    if (Areas.Backend.Models.DataAccess.MemberDAO.SysCurrent != null)
                    {
                        tableObj["Creator"] = Areas.Backend.Models.DataAccess.MemberDAO.SysCurrent.Id;
                    }
                    else
                    {
                        tableObj["Creator"] = 0;
                    }
                    tableObj["CreateTime"] = DateTime.Now;
                    if (Areas.Backend.Models.DataAccess.MemberDAO.SysCurrent != null)
                    {
                        tableObj["Modifier"] = WorkV3.Areas.Backend.Models.DataAccess.MemberDAO.SysCurrent.Id;
                    }
                    else
                    {
                        tableObj["Modifier"] = 0;
                    }
                    tableObj["ModifyTime"] = DateTime.Now;
                    tableObj.Insert();
                    return(item);
                }
            }
            //return new MailTemplateSetModels();
        }