예제 #1
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);
        }