Esempio n. 1
0
        /// <summary>
        /// The previewButton_Click server event handler on this page is used
        /// to handle the scenario where a user clicks the "preview"
        /// button to see a preview of the message.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void previewButton_Click(object sender, System.EventArgs e)
        {
            SmtpMail.SmtpServer = Rainbow.Settings.Portal.SmtpServer;

            CreatedDate.Text = Esperantus.Localize.GetString("NEWSLETTER_LOCALTIME", "Local time: ") + DateTime.Now.ToLongDateString();

            NewsletterDB newsletter = new NewsletterDB();

            string email;
            string name;
            string password;

            if (!bool.Parse(Settings["TestMode"].ToString()))
            {
                SqlDataReader dReader = newsletter.GetUsersNewsletter(portalSettings.PortalID, Int32.Parse(Settings["NEWSLETTER_USERBLOCK"].ToString()), Int32.Parse(Settings["NEWSLETTER_DONOTRESENDWITHIN"].ToString()));
                try
                {
                    if (dReader.Read())
                    {
                        email    = dReader["Email"].ToString();
                        name     = dReader["Name"].ToString();
                        password = dReader["Password"].ToString();
                    }
                    else
                    {
                        lblMessage.Text = Esperantus.Localize.GetString("NEWSLETTER_NORECIPIENTS", "No recipients");
                        return;                         //nothing more to do here
                    }
                }
                finally
                {
                    dReader.Close();                     //by Manu, fixed bug 807858
                }
            }
            else
            {
                email    = txtEMail.Text;
                name     = txtName.Text;
                password = "******";                 //Fake password
            }

            EditPanel.Visible    = false;
            PrewiewPanel.Visible = true;
            UsersPanel.Visible   = false;
            lblFrom.Text         = txtName.Text + " (" + txtEMail.Text + ")";
            lblTo.Text           = name + " (" + email + ")";
            lblSubject.Text      = txtSubject.Text;
            string body = newsletter.SendMessage(txtEMail.Text, email, name, password, Settings["NEWSLETTER_LOGINHOMEPAGE"].ToString(), txtSubject.Text, txtBody.Text, false, HtmlMode.Checked, InsertBreakLines.Checked);

            if (HtmlMode.Checked)
            {
                lblBody.Text = body;
            }
            else
            {
                lblBody.Text = "<PRE>" + body + "</PRE>";
            }
        }
Esempio n. 2
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            // Added EsperantusKeys for Localization
            // Mario Endara [email protected] 11/05/2004
            Titulo = Esperantus.Localize.GetString("NEWSLETTER_TITLE");

            if (!Page.IsPostBack)
            {
                CreatedDate.Text = DateTime.Now.ToLongDateString();

                //Set default
                txtName.Text  = Settings["NEWSLETTER_DEFAULTNAME"].ToString();
                txtEMail.Text = Settings["NEWSLETTER_DEFAULTEMAIL"].ToString();
                if (txtEMail.Text == string.Empty)
                {
                    txtEMail.Text = PortalSettings.CurrentUser.Identity.Email;
                }

                //create a DataTable
                DataTable dt = new DataTable();
                dt.Columns.Add(new DataColumn("StringValue"));

                NewsletterDB newsletter = new NewsletterDB();

                if (!bool.Parse(Settings["TestMode"].ToString()))
                {
                    SqlDataReader dReader = newsletter.GetUsersNewsletter(portalSettings.PortalID, Int32.Parse(Settings["NEWSLETTER_USERBLOCK"].ToString()), Int32.Parse(Settings["NEWSLETTER_DONOTRESENDWITHIN"].ToString()));
                    try
                    {
                        while (dReader.Read())
                        {
                            DataRow dr = dt.NewRow();
                            dr[0] = "<b>" + dReader["Name"].ToString() + ":</b> " + dReader["EMail"].ToString();
                            dt.Rows.Add(dr);
                        }
                    }
                    finally
                    {
                        dReader.Close();                         //by Manu, fixed bug 807858
                    }

                    DataList1.DataSource      = new DataView(dt);
                    DataList1.RepeatDirection = RepeatDirection.Vertical;
                    DataList1.RepeatLayout    = RepeatLayout.Table;
                    DataList1.BorderWidth     = Unit.Pixel(1);
                    DataList1.GridLines       = GridLines.Both;
                    DataList1.RepeatColumns   = 3;
                    DataList1.DataBind();
                    DataList1.Visible = true;

                    int cnt = newsletter.GetUsersNewsletterCount(portalSettings.PortalID, Int32.Parse(Settings["NEWSLETTER_USERBLOCK"].ToString()), Int32.Parse(Settings["NEWSLETTER_DONOTRESENDWITHIN"].ToString()));
                    // Added EsperantusKeys for Localization
                    // Mario Endara [email protected] 11/05/2004
                    lblMessage.Text = Esperantus.Localize.GetString("NEWSLETTER_MSG").Replace("{1}", cnt.ToString());
                }
                else
                {
                    // Added EsperantusKeys for Localization
                    // Mario Endara [email protected] 11/05/2004
                    lblMessage.Text = Esperantus.Localize.GetString("NEWSLETTER_MSG_TEST").Replace("{1}", txtName.Text).Replace("{2}", txtEMail.Text);
                }

                //Try to get template
                int HTMLModID = int.Parse(Settings["NEWSLETTER_HTMLTEMPLATE"].ToString());
                if (HTMLModID > 0)
                {
                    // Obtain the selected item from the HtmlText table
                    Newsletter.NewsletterHtmlTextDB text = new Newsletter.NewsletterHtmlTextDB();
                    SqlDataReader dr = text.GetHtmlText(HTMLModID, WorkFlowVersion.Staging);
                    try
                    {
                        if (dr.Read())
                        {
                            string buffer = (string)dr["DesktopHtml"];
                            // Replace relative path to absolute path. [email protected] 19/07/2004
                            buffer = buffer.Replace(Rainbow.Settings.Path.ApplicationFullPath, Rainbow.Settings.Path.ApplicationRoot);
                            if (Rainbow.Settings.Path.ApplicationRoot.Length > 0)                             //by Manu... on root PortalSettings.ApplicationPath is empty
                            {
                                buffer = buffer.Replace(Rainbow.Settings.Path.ApplicationRoot, Rainbow.Settings.Path.ApplicationFullPath);
                            }

                            txtBody.Text     = Server.HtmlDecode(buffer);
                            HtmlMode.Checked = true;
                        }
                        else
                        {
                            HtmlMode.Checked = false;
                        }
                    }
                    finally
                    {
                        dr.Close();
                    }
                }
            }
            EditPanel.Visible    = true;
            PrewiewPanel.Visible = false;
            UsersPanel.Visible   = true;
        }
Esempio n. 3
0
        /// <summary>
        /// The SubmitBtn_Click server event handler on this page is used
        /// to handle the scenario where a user clicks the "send"
        /// button after entering a response to a message post.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void submitButton_Click(object sender, System.EventArgs e)
        {
            string message;
            int    cnt = 0;

            EditPanel.Visible    = false;
            PrewiewPanel.Visible = true;
            UsersPanel.Visible   = false;

            SmtpMail.SmtpServer = Rainbow.Settings.Portal.SmtpServer;

            message = Esperantus.Localize.GetString("NEWSLETTER_SENDTO", "<b>Message:</b> sent to:<br>");

            try
            {
                NewsletterDB newsletter = new NewsletterDB();
                if (!bool.Parse(Settings["TestMode"].ToString()))
                {
                    // Get Newsletter Users from DB
                    SqlDataReader dReader = newsletter.GetUsersNewsletter(portalSettings.PortalID, Int32.Parse(Settings["NEWSLETTER_USERBLOCK"].ToString()), Int32.Parse(Settings["NEWSLETTER_DONOTRESENDWITHIN"].ToString()));
                    try
                    {
                        while (dReader.Read())
                        {
                            cnt++;
                            message += dReader["Email"].ToString() + ", ";
                            try
                            {
                                //Send the email
                                newsletter.SendMessage(txtEMail.Text, dReader["Email"].ToString(), dReader["Name"].ToString(), dReader["Password"].ToString(), Settings["NEWSLETTER_LOGINHOMEPAGE"].ToString(), txtSubject.Text, txtBody.Text, true, HtmlMode.Checked, InsertBreakLines.Checked);
                                //Update db
                                newsletter.SendNewsletterTo(portalSettings.PortalID, dReader["Email"].ToString());
                            }
                            catch (Exception ex)
                            {
                                InvalidRecipients += dReader["Email"].ToString() + "<br>";
                                BlacklistDB.AddToBlackList(portalSettings.PortalID, dReader["Email"].ToString(), ex.Message);
                            }
                        }
                    }
                    finally
                    {
                        dReader.Close();                         //by Manu, fixed bug 807858
                    }
                    lblMessage.Text = Esperantus.Localize.GetString("NEWSLETTER_SENDINGTO", "Message has been sent to {1} registered users.").Replace("{1}", cnt.ToString());
                }
                else
                {
                    newsletter.SendMessage(txtEMail.Text, txtEMail.Text, txtName.Text, "******", Settings["NEWSLETTER_LOGINHOMEPAGE"].ToString(), txtSubject.Text, txtBody.Text, true, HtmlMode.Checked, InsertBreakLines.Checked);
                    lblMessage.Text = Esperantus.Localize.GetString("NEWSLETTER_TESTSENDTO", "Test message sent to: ") + txtName.Text + " [" + txtEMail.Text + "]";
                }
            }
            catch (Exception ex)
            {
                lblMessage.Text = Esperantus.Localize.GetString("NEWSLETTER_ERROR", "An error occurred: ") + ex.Message;
            }

            CreatedDate.Text = Esperantus.Localize.GetString("NEWSLETTER_SENDDATE", "Message sent: ") + DateTime.Now.ToLongDateString() + "<br>";

            if (InvalidRecipients.Length > 0)
            {
                CreatedDate.Text += Esperantus.Localize.GetString("NEWSLETTER_INVALID_RECIPIENTS", "Invalid recipients:<br>") + InvalidRecipients;
            }

            //Hides commands
            submitButton.Visible  = false;
            cancelButton2.Visible = false;
        }