示例#1
0
        private void SendEmail(MembershipUser sender)
        {
            string mailFile = Server.MapPath("~/App_Data/ChangeMail.html");

            string strSubject = "Sent From " + Regex.Replace(Config.ForumTitle, @"&\w+;", "") + ": Email change request";

            var builder = new UriBuilder("http",
                                         Request.Url.DnsSafeHost,
                                         Request.Url.Port, Page.ResolveUrl("~/Account/activate.aspx"), string.Format("?C={0}&E=T", SnitzMembershipProvider.CreateValidationCode(sender)));

            var    file    = new StreamReader(mailFile);
            string msgBody = file.ReadToEnd();

            msgBody = msgBody.Replace("<%UserName%>", sender.UserName);
            msgBody = msgBody.Replace("<%ForumTitle%>", Config.ForumTitle);
            msgBody = msgBody.Replace("<%validationURL%>", builder.Uri.AbsoluteUri);

            var mailsender = new SnitzEmail
            {
                toUser   = new MailAddress(newemail.Text, sender.UserName),
                FromUser = "******",
                subject  = strSubject,
                msgBody  = msgBody
            };

            mailsender.Send();
        }
示例#2
0
        public string SendPrivateMessage(string touser, string message, string subject, string layout)
        {
            string         username    = HttpContext.Current.User.Identity.Name;
            MembershipUser currentUser = Membership.GetUser(username);
            ProfileCommon  profile     = ProfileCommon.GetUserProfile(username);

            if (currentUser == null || currentUser.ProviderUserKey == null)
            {
                return(null);
            }

            var pm = new PrivateMessageInfo
            {
                Subject      = subject,
                Message      = message,
                ToMemberId   = Convert.ToInt32(touser),
                FromMemberId = (int)currentUser.ProviderUserKey,
                Read         = 0,
                OutBox       = layout != "none" ? 1 : 0,
                SentDate     = DateTime.UtcNow.ToForumDateStr(),
                Mail         = profile.PMEmail == null ? 0 : profile.PMEmail.Value
            };

            PrivateMessages.SendPrivateMessage(pm);

            //do we need to send an email
            MembershipUser toUser = Membership.GetUser(Convert.ToInt32(touser));

            if (toUser != null && Config.UseEmail)
            {
                ProfileCommon toprofile = ProfileCommon.GetUserProfile(toUser.UserName);
                if (toprofile.PMEmail.HasValue)
                {
                    if (toprofile.PMEmail.Value == 1)
                    {
                        SnitzEmail notification = new SnitzEmail
                        {
                            FromUser = "******",
                            toUser   = new MailAddress(toUser.Email),
                            subject  = Regex.Replace(Config.ForumTitle, @"&\w+;", "") + " - New Private message"
                        };
                        string strMessage = "Hello " + toUser.UserName;
                        strMessage = strMessage + username + " has sent you a private message at " + Config.ForumTitle + "." + Environment.NewLine;
                        if (String.IsNullOrEmpty(subject))
                        {
                            strMessage = strMessage + "Regarding - " + subject + "." + Environment.NewLine + Environment.NewLine;
                        }
                        else
                        {
                            strMessage = strMessage + "With the subject entitled - " + message + "." + Environment.NewLine + Environment.NewLine;
                        }

                        notification.msgBody = strMessage;
                        notification.Send();
                    }
                }
            }
            return(PrivateMessage.PmSent);
        }
示例#3
0
    protected void EmailConfirmation(string username)
    {
        //todo: load text files from app_data folder;

        MembershipUser mu         = Membership.GetUser(username, false);
        SnitzEmail     mailsender = new SnitzEmail
        {
            toUser   = new MailAddress(mu.Email, mu.UserName),
            FromUser = Resources.extras.lblAdministrator,
            subject  = Resources.extras.RegApproval,
            IsHtml   = true,
            msgBody  = LoadApprovalTemplate(mu)
        };

        mailsender.Send();
    }
示例#4
0
        public string SendEmail(string name, string email, string message, string subject)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new Exception("You must supply a name.");
            }

            if (string.IsNullOrEmpty(email))
            {
                MembershipUser mu = Membership.GetUser(name, false);
                if (mu == null)
                {
                    throw new Exception("You must supply an email address.");
                }
                email = mu.Email;
            }

            if (string.IsNullOrEmpty(message))
            {
                throw new Exception("Please provide a message to send.");
            }

            string strSubject;

            if (String.IsNullOrEmpty(subject))
            {
                strSubject = "Sent From " + Regex.Replace(Config.ForumTitle, @"&\w+;", "") + " by " + HttpContext.Current.User.Identity.Name;
            }
            else
            {
                strSubject = subject;
            }

            var mailsender = new SnitzEmail
            {
                toUser   = new MailAddress(email, name),
                FromUser = HttpContext.Current.User.Identity.Name,
                subject  = strSubject,
                IsHtml   = false,
                msgBody  = message
            };

            mailsender.Send();
            return("Your Email has been sent successfully");
        }
示例#5
0
    private void SendEmail(string user, string password)
    {
        string       mailFile   = Server.MapPath("~/App_Data/AdminRegisterMail.html");
        string       strSubject = "Sent From " + Config.ForumTitle;
        StreamReader file       = new StreamReader(mailFile);
        string       msgBody    = file.ReadToEnd();

        msgBody = msgBody.Replace("<%UserName%>", user);
        msgBody = msgBody.Replace("<%Password%>", password);
        msgBody = msgBody.Replace("<%ForumTitle%>", Config.ForumTitle);
        msgBody = msgBody.Replace("<%ForumUrl%>", Config.ForumUrl);

        MembershipUser mu         = Membership.GetUser(user, false);
        SnitzEmail     mailsender = new SnitzEmail
        {
            toUser   = new MailAddress(mu.Email, mu.UserName),
            FromUser = "******",
            subject  = strSubject,
            IsHtml   = true,
            msgBody  = msgBody
        };

        mailsender.Send();
    }
示例#6
0
        private static void SendSubscriptions(Enumerators.Subscription subType, TopicInfo topic, ReplyInfo reply, HttpContext context)
        {
            int replyid  = -1;
            int authorid = topic.AuthorId;

            int[]         memberids  = { };
            StringBuilder Message    = new StringBuilder("<html><body>Hello {0}");
            string        strSubject = String.Empty;

            HttpContext.Current = context;
            if (reply != null)
            {
                replyid  = reply.Id;
                authorid = reply.AuthorId;
            }
            Message.Append("<br/><p>");

            ISubscription dal = Factory <ISubscription> .Create("Subscription");

            switch (subType)
            {
            case Enumerators.Subscription.ForumSubscription:

                memberids = dal.GetForumSubscriptionList(topic.ForumId);

                if (memberids.Length > 0)
                {
                    strSubject = Config.ForumTitle.Replace("&trade;", "").Replace("&copy;", "") + " - New posting";

                    Message.AppendFormat(
                        "{0} has posted to the forum {1} at {2} that you requested notification on.",
                        topic.AuthorName, topic.Forum.Subject, Config.ForumTitle);
                }
                break;

            case Enumerators.Subscription.TopicSubscription:

                memberids = dal.GetTopicSubscriptionList(topic.Id);

                if (memberids.Length > 0)
                {
                    strSubject = Config.ForumTitle.Replace("&trade;", "").Replace("&copy;", "") + " - Reply to a posting";
                    Message.AppendFormat("{0} has replied to a topic on <b>{1}</b> that you requested notification to.", reply.AuthorName, Config.ForumTitle);
                }

                break;
            }
            Message.AppendFormat(" Regarding the subject - {0}.", topic.Subject);
            Message.Append("<br/>");
            Message.Append("<br/>");
            Message.AppendFormat("You can view the posting <a href=\"{0}Content/Forums/topic.aspx?whichpage=-1&TOPIC={1}", Config.ForumUrl, topic.Id);
            if (replyid > 0)
            {
                Message.AppendFormat("#{0}", replyid);
            }
            Message.Append("\">here</a>");
            Message.Append("</p></body></html>");
            foreach (int id in memberids)
            {
                MemberInfo member = Members.GetMember(id);
                //don't send the author notification of their own posts
                if (id == authorid)
                {
                    continue;
                }
                SnitzEmail email = new SnitzEmail
                {
                    subject  = strSubject,
                    msgBody  = String.Format(Message.ToString(), member.Username),
                    toUser   = new MailAddress(member.Email, member.Username),
                    IsHtml   = true,
                    FromUser = "******"
                };
                email.Send();
            }
        }
示例#7
0
        private void ProcessModeration(int mode, int topicid, int replyid, int adminmodid, string comments)
        {
            ReplyInfo      reply = null;
            MembershipUser author;

            var moderator = Membership.GetUser(adminmodid);

            int forumId;

            var topic = Topics.GetTopic(topicid);

            if (replyid > 0)
            {
                reply = Replies.GetReply(replyid);
            }
            if (reply == null)
            {
                forumId = topic.ForumId;
                author  = Membership.GetUser(topic.AuthorId, false);
            }
            else
            {
                forumId = reply.ForumId;
                author  = Membership.GetUser(reply.AuthorId, false);
            }
            var forum = Forums.GetForum(forumId);

            var strSubject = new StringBuilder();

            strSubject.AppendFormat("{0} - Your post ", Regex.Replace(Config.ForumTitle, @"&\w+;", ""));
            if (mode == 1)
            {
                strSubject.AppendLine("has been approved ");
            }
            else if (mode == 2)
            {
                strSubject.AppendLine("has been placed on hold ");
            }
            else
            {
                strSubject.AppendLine("has been rejected ");
            }
            var strMessage = new StringBuilder();

            strMessage.AppendFormat("Hello {0}.", author.UserName).AppendLine().AppendLine();
            strMessage.Append("You made a ");

            if (replyid == 0)
            {
                strMessage.Append("post ");
            }
            else
            {
                strMessage.Append("reply to the post ");
            }
            strMessage.AppendFormat("in the {0} forum entitled {1}. {2} has decided to ", forum.Subject, moderator.UserName);

            if (mode == 1)
            {
                strMessage.Append("approve your post ");
            }
            else if (mode == 2)
            {
                strMessage.Append("place your post on hold ");
            }
            else
            {
                strMessage.Append("reject your post ");
            }
            strMessage.AppendLine("for the following reason:").AppendLine();
            strMessage.AppendLine(comments).AppendLine();
            strMessage.AppendFormat("If you have any questions, please contact {0} at {1}", moderator.UserName, moderator.Email).AppendLine();

            var mailsender = new SnitzEmail
            {
                toUser   = new MailAddress(author.Email, author.UserName),
                FromUser = "******",
                IsHtml   = false,
                subject  = strSubject.ToString(),
                msgBody  = strMessage.ToString()
            };

            mailsender.Send();
        }
示例#8
0
        private void EditTopic()
        {
            #region check for changes to poll

            var pollregex = new Regex(@"(?<poll>\[poll=\x22(?<question>.+?)\x22](?<answers>.+?)\[\/poll])",
                                      RegexOptions.Singleline);

            if (pollregex.IsMatch(Message.Text))
            {
                string topicPoll = pollregex.Match(Message.Text).Value;
                if (topicPoll == "" || topicPoll == "remove")
                {
                    if (_thisTopic.PollId.HasValue)
                    {
                        Polls.DeleteTopicPoll(_thisTopic.PollId.Value);
                    }
                }
                else if (_thisTopic.Forum.AllowPolls)
                {
                    var answers = new Regex(@"\[\*=(?<sort>[0-9]+)](?<answer>.+?)\[/\*]",
                                            RegexOptions.Singleline | RegexOptions.ExplicitCapture);
                    string question = "";
                    var    choices  = new SortedList <int, string>();

                    MatchCollection mc = pollregex.Matches(topicPoll);
                    if (mc.Count > 0)
                    {
                        foreach (Match m in mc)
                        {
                            question = m.Groups["question"].Value;
                            string answer = m.Groups["answers"].Value;

                            MatchCollection ans = answers.Matches(answer);
                            foreach (Match match in ans)
                            {
                                choices.Add(Convert.ToInt32(match.Groups["sort"].Value), match.Groups["answer"].Value);
                            }
                        }
                        if (_thisTopic.PollId.HasValue)
                        {
                            Polls.UpdateTopicPoll(_thisTopic.PollId.Value, question, choices);
                        }
                    }
                }
                Message.Text = pollregex.Replace(Message.Text, "");
            }

            #endregion

            int oldforumId = _thisTopic.ForumId;
            Topics.Update(_thisTopic.Id, Message.Text, tbxSubject.Text, Member, IsAdministrator, cbxSig.Checked);
            if (ForumDropDown.SelectedValue != oldforumId.ToString() && ForumDiv.Visible)
            {
                //move the topic
                int forumid = Convert.ToInt32(ForumDropDown.SelectedValue);
                Topics.ChangeTopicForum(_thisTopic.Id, forumid);
                Snitz.BLL.Admin.UpdateForumCounts();
                object obj = -1;
                Cache["RefreshKey"] = obj;
                _thisTopic.Author   = Members.GetAuthor(_thisTopic.AuthorId);

                if (Config.MoveNotify && _thisTopic.Author.Status != 0)
                {
                    _forum = Forums.GetForum(forumid);
                    string mailFile   = ConfigurationManager.AppSettings["TopicMoveEmail"];
                    string strSubject = "Sent From " + Regex.Replace(Config.ForumTitle, @"&\w+;", "") + ": Topic move notification";

                    var builder = new UriBuilder("http",
                                                 Request.Url.DnsSafeHost,
                                                 Request.Url.Port, Page.ResolveUrl("~/Content/Forums/forum.aspx"), string.Format("?FORUM={0}", _forum.Id));

                    var    file    = new StreamReader(mailFile);
                    string msgBody = file.ReadToEnd();
                    msgBody = msgBody.Replace("<%UserName%>", _thisTopic.AuthorName);
                    msgBody = msgBody.Replace("<%ForumUrl%>", Config.ForumTitle);
                    msgBody = msgBody.Replace("<%TopicSubject%>", _thisTopic.Subject);
                    msgBody = msgBody.Replace("<%MovedTo%>", _forum.Subject);
                    msgBody = msgBody.Replace("<%URL%>", builder.Uri.AbsoluteUri);

                    var mailsender = new SnitzEmail
                    {
                        toUser   = new MailAddress(_thisTopic.Author.Email, _thisTopic.AuthorName),
                        FromUser = "******",
                        subject  = strSubject,
                        IsHtml   = true,
                        msgBody  = msgBody
                    };
                    mailsender.Send();
                }
            }
            if (cbxLock.Checked && _inModeratedList)
            {
                Topics.SetTopicStatus(_thisTopic.Id, (int)Enumerators.PostStatus.Closed);
            }
            if (_inModeratedList)
            {
                Topics.MakeSticky(_thisTopic.Id, cbxSticky.Checked);
            }

            if (pingSiteMap)
            {
                Ping("");
            }
            InvalidateForumCache();
            Response.Redirect("/Content/Forums/topic.aspx?TOPIC=" + _thisTopic.Id);
        }