using System; using System.Configuration; using System.Data; using System.Web; using System.Web.Mail; using System.Text; using System.IO; using CommunityServer.Blogs.Components; using CommunityServer.Components; namespace CommunityServer.Blogs.DBVT { /// /// Summary description for Email. /// public class Email { private Email() {} public static void SendCommentToAdmin(WeblogPost post) { string To = "you@youremail.com"; // easily obtainable dynamically from parent WeblogPost or post.Section object string From = "someaddress@yourdomain.com"; // we don't have the user's email address if they aren't logged in. To be modified later. string Subject = String.Format("New Blog Comment: {0}", post.Subject); send(To,From,Subject,MakeBody(post)); } private static void send(string To, string From, string Subject, string Body) { SiteSettings site = SiteSettingsManager.GetSiteSettings(); MailMessage msg = new MailMessage(); msg.To = To; msg.From = From; msg.Subject = Subject; msg.Body = Body; msg.BodyFormat = MailFormat.Html; SmtpMail.SmtpServer = site.SmtpServer; SmtpMail.Send(msg); } private static string MakeBody(WeblogPost post) { // Only CS post-related information shown. // parent WeblogPost object created to obtain URL of original post. MostRecentPostAuthorID is going to always be // blog admin ID for single author blog. Perhaps an override on the WeblogPosts.GetPost() method? WeblogPost parentpost = WeblogPosts.GetPost(post.ParentID,post.Section.MostRecentPostAuthorID,false,true,true); // We're using a new AppSettings value here. Probably a better way. Don't forget to add to your root/web.config if you go this route string siteURL = "http://" + ConfigurationSettings.AppSettings["CSServerHost"].ToString(); StringBuilder sb = new StringBuilder(); sb.Append("Comment from " + post.SubmittedUserName); sb.Append(post.FormattedBody); // Notice the "Reply to this comment" URL created from the parent WeblogPost object sb.Append("Reply to this comment"); sb.Append("Posted @ " + post.PostDate); return sb.ToString(); } } }