private static void EmailCommentToAdmin(FeedbackItem comment, BlogInfo currentBlog)
{
string blogTitle = currentBlog.Title;
// create and format an email to the site admin with comment details
EmailProvider im = EmailProvider.Instance();
string fromEmail = comment.Email;
if (String.IsNullOrEmpty(fromEmail))
fromEmail = null;
string to = currentBlog.Email;
string from = fromEmail ?? im.AdminEmail;
string subject = String.Format(CultureInfo.InvariantCulture, "Comment: {0} (via {1})", comment.Title, blogTitle);
if (comment.FlaggedAsSpam)
subject = "[SPAM Flagged] " + subject;
string commenterUrl = "none given";
if(comment.SourceUrl != null)
commenterUrl = comment.SourceUrl.ToString();
string bodyFormat = "{7}Comment from {0}" + Environment.NewLine
+ "----------------------------------------------------" + Environment.NewLine
+ "From:\t{1} <{2}>" + Environment.NewLine
+ "Url:\t{3}" + Environment.NewLine
+ "IP:\t{4}" + Environment.NewLine
+ "====================================================" + Environment.NewLine + Environment.NewLine
+ "{5}" + Environment.NewLine + Environment.NewLine
+ "Source: {6}";
string body = string.Format(CultureInfo.InvariantCulture, bodyFormat,
blogTitle,
comment.Author,
fromEmail ?? "no email given",
commenterUrl,
comment.IpAddress,
// we're sending plain text email by default, but body includes <br />s for crlf
comment.Body.Replace("<br />", Environment.NewLine).Replace("<br />", Environment.NewLine),
currentBlog.UrlFormats.FeedbackFullyQualifiedUrl(comment.EntryId, comment.parentEntryName, comment.ParentDateCreated, comment),
comment.FlaggedAsSpam ? "Spam Flagged " : string.Empty);
try
{
SendEmailDelegate sendEmail = im.Send;
AsyncHelper.FireAndForget(sendEmail, to, from, subject, body);
}
catch(Exception e)
{
log.Warn("Could not email comment to admin", e);
}
}