Ejemplo n.º 1
0
    private bool SendEmail()
    {
        string strMailBody = "";
        string strRptTitle = "";
        bool bIsTaskRpt = false;
        bool bIsRptTitleFound = false;
        int llpos = 0;
        string strtemp = "";
        int lid = 0;
        int llanguage = 0;
        string strHttpType = HttpContext.Current.Request.Url.Scheme + "://";

        try
        {
            if (strTargUserEmail.ToString() != "")
            {
                objMailServ = m_refSiteApi.EkMailRef;

                objMailServ.MailTo = strTargUserEmail.ToString();
                objMailServ.MailFrom = m_refMail.GetSendersEmailAddress();

                if (objMailServ.MailFrom == "")
                {
                    if (!(Request.Form["frmEmailAddr"] == null))
                    {
                        objMailServ.MailFrom = Request.Form["frmEmailAddr"];
                    }
                    else
                    {
                        if (Request.QueryString["sndrEmail"] == null)
                        {
                            EmailData.Text = "<table><tr><td><input type=\"text\" id=\"frmEmailAddr\"></td><td><font color=\"red\">" + m_refMsg.GetMessage("msg enter email") + "</font></td></tr></table>";
                            return (true);
                        }
                        else
                        {
                            objMailServ.MailFrom = Request.QueryString["sndrEmail"];
                        }
                    }
                }

                if (!(Request.Form["attRptHtml"] == null))
                {
                    strMailBody = (string)(Request.Form["attRptHtml"].ToString());
                }

                if (!(Request.Form["setRptTitle"] == null))
                {
                    if (!(Request.QueryString["rptstatus"] == null) && "siteupdateactivity" == Request.QueryString["rptstatus"])
                    {
                        bIsTaskRpt = false;
                        objMailServ.MailSubject = "Site Activity Report";
                        bIsRptTitleFound = true;
                    }
                    else if ((Request.Form["setRptTitle"].IndexOf("Content") == -1) && (Request.Form["setRptTitle"].IndexOf("Refresh") == -1) && (Request.Form["setRptTitle"].IndexOf("Site") == -1) && (Request.Form["setRptTitle"].IndexOf("Asynchronous") == -1) && (Request.Form["setRptTitle"].IndexOf("Preapproval") == -1))
                    {
                        // It is the Task report. Get title from the MailBody
                        strRptTitle = GetTaskWorkAreaTitleBar(strMailBody);
                        bIsTaskRpt = true;
                        objMailServ.MailSubject = strRptTitle;
                        bIsRptTitleFound = true;
                    }
                    else if (!(Request.Form["setRptTitle"].IndexOf("Preapproval") == -1))
                    {
                        strRptTitle = "Content Reports: Preapproval Groups Report";
                        bIsTaskRpt = true;
                        objMailServ.MailSubject = strRptTitle;
                        bIsRptTitleFound = true;
                    }
                    else
                    {
                        // It is the content report. Should have a report title from LoadUserListChildPage.
                        if (Request.Form["setRptTitle"] != "")
                        {
                            objMailServ.MailSubject = Request.Form["setRptTitle"];
                            bIsRptTitleFound = true;
                        }
                    }
                }

                if ((!(bIsRptTitleFound)) || (objMailServ.MailSubject.Trim() == ""))
                {
                    //In case no title found, add a default one to avoid send mail failure
                    if (m_sRptStatus == "viewsearchphrasereport")
                    {
                        objMailServ.MailSubject = "Search Phrase Report";
                    }
                    else
                    {
                        objMailServ.MailSubject = "Report";
                    }
                }

                string msgNoData = m_refMsg.GetMessage("msg no data report");
                if (strMailBody != "")
                {
                    if (bIsTaskRpt)
                    {
                        // remove checkbox and images from the report
                        strMailBody = (string)(RemoveItemsFromReport(strMailBody, "checkbox", "<INPUT", ">"));
                        // Remove images from task reports & set task report title exclude the reports containing word content, site, refresh

                        strMailBody = (string)(RemoveItemsFromReport(strMailBody, "<IMG", "<IMG", ">"));
                        // remove extra email button and other stuff from task report
                        strMailBody = (string)(RemoveItemsFromReport(strMailBody, "class=title-header", "<TABLE", ""));
                        // remove the links on the user names, inline javascript functions, hidden variables
                        strMailBody = (string)(RemoveItemsFromReport(strMailBody, "href=\"#\"", "<A", ">"));
                        strMailBody = (string)(RemoveItemsFromReport(strMailBody, "AddShownTaskID(", "<SCRIPT", "SCRIPT>"));
                        strMailBody = (string)(RemoveItemsFromReport(strMailBody, "text/javascript", "<SCRIPT", "SCRIPT>"));
                        strMailBody = (string)(RemoveItemsFromReport(strMailBody, "type=hidden", "<INPUT", ">"));
                        // remove links on the titles that do sorting
                        strMailBody = (string)(RemoveItemsFromReport(strMailBody, "sort\">", "<A", ">"));
                        //remove invisible fields
                        strMailBody = (string)(RemoveItemsFromReport(strMailBody, "style=\"DISPLAY: none\">", "<TR", "/TR>"));
                        strMailBody = (string)(RemoveItemsFromReport(strMailBody, "ektronTitlebar", "<DIV", "/DIV>"));
                        strMailBody = (string)(RemoveItemsFromReport(strMailBody, "setTaskStateForSelTasks(", "<TABLE", "/TABLE>"));
                        strMailBody = (string)(RemoveItemsFromReport(strMailBody, "RefreshTasksWithTaskType(", "<TABLE", "/TABLE>"));

                        // replace the occurrences of any aspx file included in the link to be the real path
                        strMailBody = strMailBody.Replace("tasks.aspx?", strHttpType + m_refUserApi.RequestInformationRef.HostUrl.ToString() + m_refUserApi.RequestInformationRef.ApplicationPath.ToString() + "tasks.aspx?");
                        strMailBody = strMailBody.Replace("content.aspx?", strHttpType + m_refUserApi.RequestInformationRef.HostUrl.ToString() + m_refUserApi.RequestInformationRef.ApplicationPath.ToString() + "content.aspx?");
                        strMailBody = strMailBody.Replace("tasks.aspx?", strHttpType + m_refUserApi.RequestInformationRef.HostUrl.ToString() + m_refUserApi.RequestInformationRef.ApplicationPath.ToString() + "tasksaction.aspx?");
                        strMailBody = strMailBody.Replace("users.aspx?", strHttpType + m_refUserApi.RequestInformationRef.HostUrl.ToString() + m_refUserApi.RequestInformationRef.ApplicationPath.ToString() + "users.aspx?");
                        if (m_sRptStatus == "viewsearchphrasereport" && strMailBody.IndexOf("<TR", System.StringComparison.OrdinalIgnoreCase) == strMailBody.LastIndexOf("<TR", System.StringComparison.OrdinalIgnoreCase))
                        {
                            strMailBody = msgNoData;
                        }
                    }
                    else
                    {
                        //This is the content report
                        // remove the links for the Last Editor and Path.
                        strMailBody = strMailBody.Replace("src=\"" + m_refUserApi.AppImgPath, "src=" + strHttpType + m_refUserApi.RequestInformationRef.HostUrl + m_refUserApi.AppImgPath);
                        var ImgUIPath = m_refUserApi.ApplicationPath + "images/ui/icons/";
                        strMailBody = strMailBody.Replace("src=\"" + ImgUIPath, "src=" + strHttpType + m_refUserApi.RequestInformationRef.HostUrl + ImgUIPath);
                        strMailBody = (string)(RemoveItemsFromReport(strMailBody, "checkbox", "<INPUT", ">"));
                        strMailBody = (string)(RemoveItemsFromReport(strMailBody, "href=\"reports.aspx?", "<A", ">"));
                        strMailBody = (string)(RemoveItemsFromReport(strMailBody, "LoadEmailChildPage(", "<A ", ">"));
                        strMailBody = (string)(RemoveItemsFromReport(strMailBody, "selectAllOrNoneWrapper", "<DIV ", "DIV>"));

                        //remove inline script functions and hidden fields
                        strMailBody = (string)(RemoveItemsFromReport(strMailBody, "SCRIPT>", "<SCRIPT", "SCRIPT>"));
                        strMailBody = (string)(RemoveItemsFromReport(strMailBody, "type=hidden", "<INPUT", ">"));
                        strMailBody = strMailBody.Replace("reports.aspx?", strHttpType + m_refUserApi.RequestInformationRef.HostUrl.ToString() + m_refUserApi.RequestInformationRef.ApplicationPath.ToString() + "workarea.aspx?page=reports.aspx&");

                        // Replace the occurrences of content.aspx & cmsform.aspx with the full server Url.
                        //strMailBody = strMailBody.Replace("reports.aspx?", "http://" & m_refUserApi.RequestInformationRef.HostUrl.ToString() & m_refUserApi.RequestInformationRef.ApplicationPath.ToString() & "workarea.aspx?page=reports.aspx&")
                        //strMailBody = strMailBody.Replace("content.aspx?", "http://" & m_refUserApi.RequestInformationRef.HostUrl.ToString() & m_refUserApi.RequestInformationRef.ApplicationPath.ToString() & "workarea.aspx?page=content.aspx&")
                        //strMailBody = strMailBody.Replace("cmsform.aspx?", "http://" & m_refUserApi.RequestInformationRef.HostUrl.ToString() & m_refUserApi.RequestInformationRef.ApplicationPath.ToString() & "workarea.aspx?page=cmsform.aspx&")

                        strMailBody = strMailBody.Replace("reports.aspx?", strHttpType + m_refUserApi.RequestInformationRef.HostUrl.ToString() + m_refUserApi.RequestInformationRef.ApplicationPath.ToString() + "reports.aspx?");

                        llpos = strMailBody.IndexOf("content.aspx?");
                        while (llpos > -1)
                        {
                            strtemp = strMailBody.Substring(llpos, System.Convert.ToInt32(strMailBody.Substring(llpos, strMailBody.Length - llpos).IndexOf(">")));
                            llpos = strtemp.IndexOf("id");
                            lid = int.Parse(strtemp.Substring(llpos + 3, System.Convert.ToInt32(strtemp.Substring(llpos, strtemp.Length - llpos).IndexOf("&") - 3)));
                            strMailBody = strMailBody.Replace(strtemp, strHttpType + m_refUserApi.RequestInformationRef.HostUrl.ToString() + m_refUserApi.RequestInformationRef.ApplicationPath.ToString() + "linkview.aspx?id=" + lid + "&viewStatus=" + m_sRptStatus + "&fromEmail=1" + "\"");
                            llpos = strMailBody.IndexOf("content.aspx?");
                        }

                        llpos = strMailBody.IndexOf("cmsform.aspx?");
                        while (llpos > -1)
                        {
                            strtemp = strMailBody.Substring(llpos, System.Convert.ToInt32(strMailBody.Substring(llpos, strMailBody.Length - llpos).IndexOf(">")));
                            llpos = strtemp.IndexOf("id");
                            lid = int.Parse(strtemp.Substring(llpos + 3, System.Convert.ToInt32(strtemp.Substring(llpos, strtemp.Length - llpos).IndexOf("&") - 3)));
                            strMailBody = strMailBody.Replace(strtemp, strHttpType + m_refUserApi.RequestInformationRef.HostUrl.ToString() + m_refUserApi.RequestInformationRef.ApplicationPath.ToString() + "linkview.aspx?ekfrm=" + lid + "&viewStatus=" + m_sRptStatus + "&fromEmail=1" + "\"");
                            llpos = strMailBody.IndexOf("cmsform.aspx?");
                        }

                        if (Request.Form["setRptTitle"].IndexOf("Approval") > -1)
                        {
                            strMailBody = (string)(RemoveItemsFromReport(strMailBody, "fldid", "<A", ">"));
                            llpos = strMailBody.IndexOf("approval.aspx?");
                            string rptContnet = "";
                            while (llpos > -1)
                            {
                                strtemp = strMailBody.Substring(llpos, System.Convert.ToInt32(strMailBody.Substring(llpos, strMailBody.Length - llpos).IndexOf(">")));
                                llpos = strtemp.IndexOf("id");
                                if (strMailBody.IndexOf("rptType") > -1)
                                {
                                    lid = int.Parse(strtemp.Substring(llpos + 3, System.Convert.ToInt32(strtemp.Substring(llpos, strtemp.Length - llpos).IndexOf("&") - 3)));
                                    llpos = strtemp.ToLower().IndexOf("langtype");
                                    if (llpos != -1)
                                    {
                                        llanguage = int.Parse(strtemp.Substring(llpos + 9, System.Convert.ToInt32(strtemp.Substring(llpos, strtemp.Length - llpos).IndexOf("&") - 9)));
                                    }
                                    llpos = strtemp.IndexOf("rptType");

                                    rptContnet = strtemp.Substring(llpos + 8, strtemp.Length - llpos - 9);
                                    if (rptContnet == "2")
                                    {
                                        strMailBody = strMailBody.Replace(strtemp, strHttpType + m_refUserApi.RequestInformationRef.HostUrl.ToString() + m_refUserApi.RequestInformationRef.ApplicationPath.ToString() + "linkview.aspx?ekfrm=" + lid + "&LangType=" + llanguage + "&viewStatus=viewApproval" + "&fromEmail=1" + "\"");
                                    }
                                    else
                                    {
                                        strMailBody = strMailBody.Replace(strtemp, strHttpType + m_refUserApi.RequestInformationRef.HostUrl.ToString() + m_refUserApi.RequestInformationRef.ApplicationPath.ToString() + "linkview.aspx?Id=" + lid + "&LangType=" + llanguage + "&viewStatus=viewApproval" + "&fromEmail=1" + "\"");
                                    }
                                }

                                llpos = strMailBody.IndexOf("approval.aspx?");
                            }
                        }
                    }
                }
                else
                {
                    strMailBody = msgNoData;
                }

                objMailServ.MailBodyText = strMailBody; //Request.Form("attRptHtml").ToString

                if (objMailServ.MailFrom != "")
                {
                    if (!(Request.QueryString["sndrEmail"] == null))
                    {
                        // We got the email address from the Email Data text box.
                        // Set the EmailData to "" to close the IFrame
                        EmailData.Text = "";
                    }
                    objMailServ.SendMail();
                    objMailServ = null;
                    // Mail Sent Successfully
                    EmailData.Text = "";
                }
                else
                {
                    throw (new Exception(m_refMsg.GetMessage("Error: Email missing source address")));
                }

            }
            else
            {
                throw (new Exception(m_refMsg.GetMessage("error: email missing target address")));
            }
            return (true);
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
        }
        finally
        {
            objMailServ = null;
        }
        //' exiting the function restores default error handling (crash script).
        //' alternately could do explicitly: on error goto 0
    }
Ejemplo n.º 2
0
    protected void RequestCheckIn()
    {
        #region Instantiate Local Variables

        long userIdFrom = Convert.ToInt64(Request.QueryString["userIdFrom"]);
        long userIdTo = Convert.ToInt64(Request.QueryString["userIdTo"]);

        ContentData myContentData = new ContentData();
        Folder myFolder = new Folder();
        FolderData myFolderData = new FolderData();
        myContentData = m_ContentApi.GetContentById(this.ContentId, ContentAPI.ContentResultType.Published);
        myFolderData = myFolder.GetFolder(myContentData.FolderId);

        #endregion

        #region Retrieve User Data

        UserData userFromData = new UserData();
        UserData userToData = new UserData();
        UserAPI myUserApi = new UserAPI();
        ContentAPI contAPI = new ContentAPI();
        userFromData = myUserApi.GetUserById(userIdFrom, true, true);
         //Calling EkUserRw instead of UserApi to skip permissions check
        Ektron.Cms.DataIO.EkUserRW usrObj = new Ektron.Cms.DataIO.EkUserRW(contAPI.RequestInformationRef);
        Microsoft.VisualBasic.Collection uCol = usrObj.GetUserByIDv2_6(userIdTo, true, true);
        userToData = usrObj.ConvertUserData(uCol);

        #endregion

        #region Send "Request Check-In" Email Message

        EkMessageHelper messageHelper = new EkMessageHelper(m_ContentApi.RequestInformationRef);
        EkMailService mail = new EkMailService(m_ContentApi.RequestInformationRef);

        if (userFromData.Email != String.Empty && userToData.Email != String.Empty)
        {
            try
            {
                mail.MailFrom = userFromData.Email;
                mail.MailCC = userFromData.Email;
                mail.MailSubject = messageHelper.GetMessageForLanguage("DmsMenuRequestCheckInSubject", this.LanguageId) + @": " + myContentData.Title;
                mail.MailBodyText = this.GetBodyText(messageHelper, myContentData, myFolderData, userFromData.FirstName, userFromData.LastName);
                mail.MailTo = userToData.Email;
                mail.SendMail();
                DmsMenuActionsRepsonse.Text = messageHelper.GetMessageForLanguage("DmsMenuRequestCheckInSucceeded", this.LanguageId) + @" " + userToData.FirstName + @" " + userToData.LastName + @" (" + userToData.Email + @")";
            }
            catch
            {
                DmsMenuActionsRepsonse.Text = messageHelper.GetMessageForLanguage("DmsMenuRequestCheckInFailed", this.LanguageId);
            }
        }
        else
        {
            DmsMenuActionsRepsonse.Text = messageHelper.GetMessageForLanguage("DmsMenuRequestCheckInFailedNoEmail", this.LanguageId);
        }

        #endregion
    }