Click here to Skip to main content
15,895,746 members
Articles / Programming Languages / C#

LumiSoft MailServer

Rate me:
Please Sign up or sign in to vote.
3.79/5 (22 votes)
17 Nov 2006CPOL1 min read 323.2K   4.9K   74  
Full featured SMTP/POP3/IMAP server
using System;
using System.IO;
using System.Data;

using LumiSoft.MailServer;
using LumiSoft.Net;
using LumiSoft.Net.Dns.Client;
using LumiSoft.Net.SMTP.Server;


namespace LumiSoft.MailServer
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	public class lsSenderFilter : ISmtpSenderFilter
	{
		/// <summary>
		/// 
		/// </summary>
		public lsSenderFilter()
		{			
		}

		/// <summary>
		/// Filters sender.
		/// </summary>
		/// <param name="from">Sender.</param>
		/// <param name="api">Reference to server API.</param>
		/// <param name="session">Reference to SMTP session.</param>
		/// <param name="errorText">Filtering error text what is returned to client. ASCII text, 100 chars maximum.</param>
		/// <returns>Returns true if sender is ok or false if rejected.</returns>
		public bool Filter(string from,IMailServerApi api,SMTP_Session session,out string errorText)
		{	
			errorText = "";
			string ip = session.RemoteEndPoint.Address.ToString();

			Dns_Client dns = new Dns_Client();
			
			bool ok = false;

			// Don't check PTR for authenticated session and LAN IP ranges
			if(session.Authenticated || ip.StartsWith("127.0.0.1") || ip.StartsWith("10.") || ip.StartsWith("192.168")){
				return true;
			}

			DnsServerResponse reponse = dns.Query(ip,QTYPE.PTR);
			if(reponse.ResponseCode == RCODE.NO_ERROR){
				foreach(PTR_Record rec in reponse.GetPTRRecords()){
					if(rec.DomainName.ToLower() == session.EhloName.ToLower()){
						ok = true;
						break;
					}
				}
			}

			if(!ok){
				errorText = "Bad EHLO/HELO name, you must have valid DNS PTR record for your EHLO name and IP.";
			}

			return ok;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Estonia Estonia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions