📄 sendcommentmail.cs
字号:
#region using
using System;
using System.Web;
using BlogEngine.Core.Web.Controls;
using BlogEngine.Core;
using System.Net.Mail;
using System.Threading;
#endregion
/// <summary>
/// Sends an e-mail to the blog owner whenever a comment is added.
/// </summary>
[Extension("Sends an e-mail to the blog owner whenever a comment is added", "", "")]
public class SendCommentMail
{
/// <summary>
/// Hooks up an event handler to the Post.CommentAdded event.
/// </summary>
public SendCommentMail()
{
Post.CommentAdded += new EventHandler<EventArgs>(Post_CommentAdded);
}
private void Post_CommentAdded(object sender, EventArgs e)
{
Post post = ((Comment)sender).Post;
if (post != null && BlogSettings.Instance.SendMailOnComment && !Thread.CurrentPrincipal.Identity.IsAuthenticated)
{
Comment comment = post.Comments[post.Comments.Count - 1];
// Trackback and pingback comments don't have a '@' symbol in the e-mail field.
string from = comment.Email.Contains("@") ? comment.Email : BlogSettings.Instance.Email;
MailMessage mail = new MailMessage();
mail.From = new MailAddress(from, comment.Author);
mail.To.Add(BlogSettings.Instance.Email);
mail.Subject = "Weblog comment on " + post.Title;
mail.Body = "Comment by " + comment.Author + " (" + comment.Email + ")" + Environment.NewLine + Environment.NewLine;
mail.Body += comment.Content + "\n\n" + post.PermaLink + "#id_" + comment.Id;
Utils.SendMailMessageAsync(mail);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -