Sep 21

It is not the way to fight spams on blogs, but for professional look for websites, duplicate comments should not be allowed. This feature is common among most popular blogs and forums, so i bring this simple extension to add this feature to BlogEngine.

To enable this extension just upload it to your extension directory under App_Code.

The extension is attached with this post.

ValidateComments.cs (1,014.00 bytes)

Sep 04

BlogEngine.NET SendMailMessage issue

Posted By Ahmed El-Kilani On 04 Sep 2009 3 Comments »
BlogEngine.NET is one of the best .NET blogs over there. I have changed to blogengine for its simplicity and themes support and customizability.
Sending mail from BlogEngine sometimes does not work. Why?
BlogEngine uses different email addresses as "Sender email" i.e "From", for example: the email of the comment poster is used as the sender notification email.
Most of the SMTP severs like godaddy only replay emails sent from only addresses hosted at the same domain as the blog is hosted, for security and spam-fighting reasons.

To fix this issue add the following to BlogSettings class under BlogEngine.Core:
/// 
/// Gets or sets the e-mail address notifications are sent from.
/// 
public string SenderEmail { get; set; }
Then we need to add the following node to settings.xml under BlogEngine.Web/App_Data
sendername@example.com
And finally a little modification in SendMailMessage method in Util class under BlogEngine.Core
/// 
/// Sends a MailMessage object using the SMTP settings.
/// 
public static void SendMailMessage(MailMessage message)
{
	if (message == null)
		throw new ArgumentNullException("message");

	try
	{
        //Override sender email which was set from contact or comment forms:
        MailAddress senderEmail = new MailAddress(BlogSettings.Instance.SenderEmail, message.From.DisplayName);
        message.From = message.ReplyTo = message.Sender = senderEmail;
		message.IsBodyHtml = true;
		message.BodyEncoding = Encoding.UTF8;
		SmtpClient smtp = new SmtpClient(BlogSettings.Instance.SmtpServer);
        // don't send credentials if a server doesn't require it,
        // linux smtp servers don't like that 
        if (!string.IsNullOrEmpty(BlogSettings.Instance.SmtpUserName)) {
		    smtp.Credentials = new System.Net.NetworkCredential(BlogSettings.Instance.SmtpUserName, BlogSettings.Instance.SmtpPassword);
        }
		smtp.Port = BlogSettings.Instance.SmtpServerPort;
		smtp.EnableSsl = BlogSettings.Instance.EnableSsl;
		smtp.Send(message);
		OnEmailSent(message);
	}
	catch (SmtpException)
	{
		OnEmailFailed(message);
	}
	finally
	{
		// Remove the pointer to the message object so the GC can close the thread.
		message.Dispose();
		message = null;
	}
}