//===============================================================
    // Function: saveButton_Click
    //===============================================================
    protected void saveButton_Click(object sender, EventArgs e)
    {
        GlobalData gd = new GlobalData((string)Session["loggedInUserFullName"]);
        gd.UpdateStringValue("BroadcastEmailContent", emailContentTextBox.Text.Trim());
        gd.UpdateStringValue("BroadcastEmailSubject", emailSubjectTextBox.Text.Trim());

        gd.UpdateStringValue("BroadcastEmailWaiting", "Y");

        Response.Redirect("main.aspx");
    }
Example #2
0
    //===============================================================
    // Function: saveButton_Click
    //===============================================================
    protected void saveButton_Click(object sender, EventArgs e)
    {
        GlobalData gd = new GlobalData((string)Session["loggedInUserFullName"]);
        gd.UpdateStringValue("PopularSearchString1", popularSearchString1TextBox.Text.Trim());
        gd.UpdateStringValue("PopularSearchString2", popularSearchString2TextBox.Text.Trim());
        gd.UpdateStringValue("PopularSearchString3", popularSearchString3TextBox.Text.Trim());
        gd.UpdateStringValue("PopularSearchString4", popularSearchString4TextBox.Text.Trim());
        gd.UpdateStringValue("PopularSearchString5", popularSearchString5TextBox.Text.Trim());

        Response.Redirect("main.aspx");
    }
Example #3
0
        //===============================================================
        // Function: SendBroadcastEmail
        //===============================================================
        public static void SendBroadcastEmail()
        {
            GlobalData gd = new GlobalData("");
            string broadcastEmailWaiting = gd.GetStringValue("BroadcastEmailWaiting");
            if (broadcastEmailWaiting == "Y")
            {
                // update this straight away - if the broadcast fails then it will not send again to all users
                gd.UpdateStringValue("BroadcastEmailWaiting", "N");

                string broadcastEmailSubject = gd.GetStringValue("BroadcastEmailSubject");
                string broadcastEmailContent = gd.GetStringValue("BroadcastEmailContent");

                string emailBodyCopy = BuildBroadcastEmail(broadcastEmailContent);

                string SMTPServer = gd.GetStringValue("SMTPServer");
                string mailFromAddress = gd.GetStringValue("MailFromAddress");
                string mailFromUsername = gd.GetStringValue("MailFromUsername");
                string mailFromPassword = gd.GetStringValue("MailFromPassword");

                // Get a list of all users
                SqlConnection conn = new SqlConnection(GlobalSettings.connectionString);
                try
                {
                    conn.Open();

                    SqlCommand cmd = new SqlCommand("", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "spSelectUserList";
                    DbDataReader rdr = cmd.ExecuteReader();
                    while (rdr.Read())
                    {
                        string emailAddress = "";
                        string firstName = "";
                        string lastName = "";

                        int userID = int.Parse(rdr["UserID"].ToString());
                        if (!rdr.IsDBNull(rdr.GetOrdinal("EmailAddress")))
                        {
                            emailAddress = (string)rdr["EmailAddress"];
                        }
                        if (!rdr.IsDBNull(rdr.GetOrdinal("FirstName")))
                        {
                            firstName = (string)rdr["FirstName"];
                        }
                        if (!rdr.IsDBNull(rdr.GetOrdinal("LastName")))
                        {
                            lastName = (string)rdr["LastName"];
                        }
                        Boolean enableSendEmails = (Boolean)rdr["EnableSendEmails"];

                        if (enableSendEmails == true)
                        {
                            try
                            {
                                //MailMessage message = new MailMessage(mailFromAddress, "*****@*****.**");
                                MailMessage message = new MailMessage(mailFromAddress, emailAddress);
                                message.ReplyTo = new MailAddress("*****@*****.**");

                                message.Subject = broadcastEmailSubject;
                                message.Body = emailBodyCopy.Replace("<<RECIPIENT>>", emailAddress);
                                message.IsBodyHtml = true;
                                SmtpClient smtp = new SmtpClient();
                                smtp.Host = SMTPServer;
                                if (mailFromPassword != "")
                                {
                                    // If the password is blank, assume mail relay is permitted
                                    smtp.Credentials = new System.Net.NetworkCredential(mailFromAddress, mailFromPassword);
                                }
                                smtp.Send(message);

                                SentEmailHistory emailHistory = new SentEmailHistory("");
                                emailHistory.subject = broadcastEmailSubject;
                                emailHistory.body = emailBodyCopy.ToString().Replace("<<RECIPIENT>>", emailAddress);
                                emailHistory.sentFrom = mailFromAddress;
                                emailHistory.sentTo = emailAddress;
                                emailHistory.Add();
                            }
                            catch (Exception ex)
                            {
                                SentEmailHistory emailHistory = new SentEmailHistory("");
                                emailHistory.subject = broadcastEmailSubject;
                                emailHistory.body = ex.Message + " -------- " + emailBodyCopy.ToString().Replace("<<RECIPIENT>>", emailAddress);
                                emailHistory.sentFrom = mailFromAddress;
                                emailHistory.sentTo = emailAddress;
                                emailHistory.Add();
                            }
                        }
                    }
                    rdr.Close();
                }
                catch (Exception ex)
                {
                    ErrorLog errorLog = new ErrorLog();
                    errorLog.WriteLog("MiscUtils", "SendBroadcastEmail", ex.Message, logMessageLevel.errorMessage);
                    throw ex;
                }
                finally
                {
                    conn.Close();
                }
            }
        }