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
        /// <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;
        }