Exemplo 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">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        private void previewButton_Click(object sender, EventArgs e)
        {
            CreatedDate.Text = General.GetString("NEWSLETTER_LOCALTIME", "Local time: ") +
                               DateTime.Now.ToLongDateString();

            NewsletterDB newsletter = new NewsletterDB();

            string email;
            string name;

            if (!bool.Parse(Settings["TestMode"].ToString()))
            {
                var users = newsletter.GetUsersNewsletter(this.PortalSettings.PortalID);
                if (users.Count > 0)
                {
                    email = users[0].Email;
                    name  = users[0].Name;
                }
                else
                {
                    lblMessage.Text = General.GetString("NEWSLETTER_NORECIPIENTS", "No recipients");
                    return; //nothing more to do here
                }
            }
            else
            {
                email = txtEMail.Text;
                name  = txtName.Text;
            }

            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, txtSubject.Text, txtBody.Text,
                                       false, HtmlMode.Checked, InsertBreakLines.Checked);

            if (HtmlMode.Checked)
            {
                lblBody.Text = body;
            }
            else
            {
                lblBody.Text = "<PRE>" + body + "</PRE>";
            }
        }
Exemplo n.º 2
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">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        private void previewButton_Click(object sender, EventArgs e)
        {
            //SmtpMail.SmtpServer = Portal.SmtpServer;
            SmtpMail.SmtpServer = Config.SmtpServer;

            CreatedDate.Text = General.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 = General.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>";
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        private void Page_Load(object sender, EventArgs e)
        {
            // Added EsperantusKeys for Localization
            // Mario Endara [email protected] 11/05/2004
            Titulo = General.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 = General.GetString("NEWSLETTER_MSG").Replace("{1}", cnt.ToString());
                }
                else
                {
                    // Added EsperantusKeys for Localization
                    // Mario Endara [email protected] 11/05/2004
                    lblMessage.Text =
                        General.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
                    NewsletterHtmlTextDB text = new 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(Path.ApplicationFullPath, Path.ApplicationRoot);
                            if (Path.ApplicationRoot.Length > 0)
                            {
                                //by Manu... on root PortalSettings.ApplicationPath is empty
                                buffer = buffer.Replace(Path.ApplicationRoot, 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;
        }
Exemplo n.º 4
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">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        private void submitButton_Click(object sender, EventArgs e)
        {
            string message;
            int    cnt = 0;

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

            SmtpMail.SmtpServer = Config.SmtpServer;

            message = General.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 =
                        General.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 = General.GetString("NEWSLETTER_TESTSENDTO", "Test message sent to: ") +
                                      txtName.Text + " [" + txtEMail.Text + "]";
                }
            }
            catch (Exception ex)
            {
                lblMessage.Text = General.GetString("NEWSLETTER_ERROR", "An error occurred: ") + ex.Message;
            }

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

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

            //Hides commands
            submitButton.Visible  = false;
            cancelButton2.Visible = false;
        }
Exemplo n.º 5
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">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        private void submitButton_Click(object sender, EventArgs e)
        {
            string message;
            int    cnt = 0;

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

            message = General.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
                    var users = newsletter.GetUsersNewsletter(this.PortalSettings.PortalID);
                    foreach (dynamic user in users)
                    {
                        cnt++;
                        message += user.Email + ", ";
                        try
                        {
                            //Send the email
                            newsletter.SendMessage(txtEMail.Text, user.Email, user.Name, txtSubject.Text,
                                                   txtBody.Text, true, HtmlMode.Checked, InsertBreakLines.Checked);
                            // Here the systems used to notify the DB that an email was sent to the user.
                            // Since we implemented the MembershipProvider for Appleseed, we doesn't have a place to store this info,
                            // thus, now the fact that an email was sent won't be persisted in the DB. However this should change in future releases.
                        }
                        catch (Exception ex)
                        {
                            InvalidRecipients += user.Email + "<br/>";
                            BlacklistDB.AddToBlackList(this.PortalSettings.PortalID, user.Email, ex.Message);
                        }
                    }
                    lblMessage.Text =
                        General.GetString("NEWSLETTER_SENDINGTO", "Message has been sent to {1} registered users.").
                        Replace("{1}", cnt.ToString());
                }
                else
                {
                    newsletter.SendMessage(txtEMail.Text, txtEMail.Text, txtName.Text, txtSubject.Text,
                                           txtBody.Text, true, HtmlMode.Checked, InsertBreakLines.Checked);
                    lblMessage.Text = General.GetString("NEWSLETTER_TESTSENDTO", "Test message sent to: ") +
                                      txtName.Text + " [" + txtEMail.Text + "]";
                }
            }
            catch (Exception ex)
            {
                lblMessage.Text = General.GetString("NEWSLETTER_ERROR", "An error occurred: ") + ex.Message;
            }

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

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

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