Exemplo n.º 1
0
        public void SendEmailToThreadTrackers(int threadId, int postId, string lang)
        {
            // The HTML template of the email that notifies the user that a post has been posted in a
            // thread he has subscribed in
            string htmlTemplate = "Hi [FIRSTNAME],<br><br>Someone has posted a new message in a discussion you are following on Ourspace. Follow the link below to see the new post: <br><br>[URL]";
            string htmlTemplateDeAt = "Hi [FIRSTNAME],<br><br>jemand hat eine neue Nachricht in einer Diskussion auf OurSpace geschrieben, der du folgst. Klick auf den folgenden Link, um diese Nachricht zu sehen: <br><br>[URL]";
            string htmlTemplatElGr = "Γεια σου [FIRSTNAME],<br><br>κάποιος έχει αναρτήσει ένα νέο μήνυμα σε μία συζήτηση του Ourspace που παρακολουθείς. Πάτησε πάνω στον παρακάτω σύνδεσμο για να δεις την καινούργια ανάρτηση: <br><br>[URL]";
            string htmlTemplateCsCz = "Ahoj [FIRSTNAME],<br><br>někdo nově reagoval na diskusi, které jste se účastnil na OurSpace. Klikněte sem, pokud chcete na diskusi přejít:<br><br>[URL]";

            String connectionString = ConfigurationManager.ConnectionStrings["SiteSqlServer"].ToString();

            string subject = "OurSpace - New post";
            string subjectDeAt = "OurSpace - Neuer Beitrag";
            string url = "";
            using (var sqlConn = new SqlConnection(connectionString))
            {
                sqlConn.Open();
                string sql = "SELECT     Forum_TrackedThreads.ForumID, Forum_TrackedThreads.ThreadID, Forum_TrackedThreads.UserID, Forum_TrackedThreads.CreatedDate, Forum_TrackedThreads.ModuleID, Users.Email, Users.FirstName, UserProfile.PropertyValue as Language, UserProfile.PropertyDefinitionID FROM   Forum_TrackedThreads INNER JOIN  Users ON Forum_TrackedThreads.UserID = Users.UserID INNER JOIN  UserProfile ON Users.UserID = UserProfile.UserID WHERE     (UserProfile.PropertyDefinitionID = 40) AND (Forum_TrackedThreads.ThreadID = " + threadId + ")";
                using (SqlCommand cmd = new SqlCommand(sql, sqlConn))
                {
                    cmd.CommandType = CommandType.Text;

                    SqlDataReader reader = cmd.ExecuteReader();
                    int i = 0;
                    List<string> emails = new List<string>();
                    // Adding the current users email to list prevents him from receiving a notification email
                    // when he posts his message
                    emails.Add(UserInfo.Email);
                    while (reader.Read())
                    {
                        string email = reader["Email"].ToString();
                        if (!emails.Contains(email))
                        {
                            int forumId = Convert.ToInt32(reader["ForumId"]);
                            string name = reader["FirstName"].ToString();
                            string language = reader["Language"].ToString();

                            Ourspace_Utilities.View util = new Ourspace_Utilities.View();
                            if (url == "")
                                url = util.GetPostUrl(forumId, postId);
                            //string lang = CultureInfo.CurrentCulture.ToString();

                            string emailMessage = "";
                            string finalSubject = "";
                            if (language == "en-GB")
                            {
                                emailMessage = htmlTemplate.Replace("[FIRSTNAME]", name).Replace("[URL]", url);
                                finalSubject = subject;
                            }
                            else if (language == "de-AT")
                            {
                                emailMessage = htmlTemplateDeAt.Replace("[FIRSTNAME]", name).Replace("[URL]", url);
                                finalSubject = subjectDeAt;
                            }
                            else
                            {
                                emailMessage = htmlTemplate.Replace("[FIRSTNAME]", name).Replace("[URL]", url);
                                finalSubject = subject;
                            }

                            try
                            {

                                //emailTask.EmailQueueTaskAdd("*****@*****.**", "OurSpace", 0, emailMessage, emailMessage, finalSubject, PortalID, forumMail.QueuePriority, objConfig.ModuleID, forumMail.EnableFriendlyToName, forumMail.DistroCall, forumMail.DistroIsSproc, forumMail.DistroParams, Date.Now(), False, "")
                                //Ourspace_Utilities.View util = new Ourspace_Utilities.View();
                                util.AddEmailToQueue("*****@*****.**", email, finalSubject, emailMessage);

                                //DotNetNuke.Services.Mail.Mail.SendEmail("*****@*****.**", email, finalSubject, emailMessage);
                            }
                            catch (Exception ex)
                            {

                            }
                        }
                    }
                    reader.Close();
                }
                sqlConn.Close();
            }
        }