Hosting Your Own Domain on a Windows Server - Part 2 of 2 - SMTP Hosting

Table of Contents

  1. Purpose
  2. Introduction
  3. Why isn't email working any more ?
  4. What can we do about it ?
  5. So what can we REALLY do about it ?
  6. Yeah, cool, you're the best programmer, but where's the beef ?
  7. Caveats, Disclaimer, TODO List
  8. Download Link
  9. Conclusion

1. Purpose top next section

To build on a Windows machine a real server for not only hosting your web sites, but also directly hosting your domain names, including e-mailboxes.

2. Introduction top previous next section

Thanks to have followed to Part 2 ;-)
In the First Part, we configured your Windows webserver to be also the DNS server for your domain names. We also did define "MX records" that specify which are the SMTP servers associated with those domains (for the purpose of receiving the emails written to your domain names' email addresses)

This won't work for the moment and it's normal. You won't receive any emails sent to your domains unless you follow this part ;-)

3. Why isn't email working any more ? top previous next section

In fact, usually, when you don't use "full DNS" from your Registrar, they cease to "own" the domain ; they can't make web redirections any more. The same can be said of email redirections. You probably - althought I have doubts - can't have email redirections without at least partly "hosting" the domain name at the Registrar's.

So let's suppose your old email redirections are "broken" and see what we can do about it.
If you write to a previously-working address (taking again the sample data used in Part 1) chances are you will now receive this kind of email answer from your ISP :

From: (Mail Delivery System)
Subject: Undelivered Mail Returned to Sender

This is the Postfix program at host

[blah blah blah]

<>: host smtp-something [some IP address] said: 550
    <>: Recipient address rejected: User unknown (in
    reply to RCPT TO command)

Alternatively, you could receive "domain unknown" and this would be almost normal.

This happens because you simply don't have an SMTP server yet, while we defined the host (same IP@ as DNS & Web server) as being one.

4. What can we do about it ? top previous next section

The solution is simple : let's find a free SMTP server and install it and voila.

Halas, the solution is not that simple : the good face of the medal of not receiving emails any more is that you don't receive spam any more :D
Too bad we need those email boxes ;-)
So first, as usual, let's find available third-party tools, free if possible, for fulfilling this "cahier des charges" :

I really checked a lot of tools offered for download all over the 'Net : in the middle of dozens of tools for would-be spammers (FreeSMTP Server, SimpleSMTP, SMTP4All, etc etc ad nauseam)- tools probably full of malwares and backdoors -, I found only a handful of tools I could consider either as small enough, or professional enough to trust them.
Quickly checking them, I discovered none fulfilled my constraints and a lot were really still oriented towards "sendind mass mailing" (in other words, spamming).
Amongst them, I gave a try to "602 LAN Suite". From the operations I conducted, I admit it does what I asked for, except that it is NOT free and will work only for 30 days ; it's not a shareware tariff, something I would have considered decent. It's 300 U$D with 1 year BitDefender updates and 60 days support. Given I had to strip it off almost all features to only keep what I needed (incoming SMTP only, addresses checking and filtering, local POP only) it's a lot for nothing. It's really a "suite", in fact probably a good "entreprise suite". Too big for me.
Back to point zero.

5. So what can we REALLY do about it ? top previous next section

As you can imagine, I was left with but one option only : do it myself :D
Thanks God, and no I won't enter technical details, there is a marvelous development environment called "Borland Delphi" which contained - theoretically - all I needed.
What you need for this is :

If ever you want to have a look at the challenge, here are tips :
-NM* components won't work
-the Indy "SMTP Demo" is incomplete - that's right - but also misleading on occasions
-don't look at the "SMTP Relay" demo, it's useless
-beware of Indy differences depending on versions
-Indy components send messages in your back, and stupid ones ("+OK Welcome to Indy SMTP Server" : how discrete :/ ) that you can't get rid of unless you rebuild a new component
-Indy components source files are available at
-you will have to implement the filesystem part, and all the exchanges in both SMTP and POP3
-not two email clients behave the same in POP
-the documentation available on the 'Net is fragmented and either outdated, or the components are outdated, or the email client is not compliant ;-)

At the end, you may end up like me with a 700 lines of aerated & documented source code program producing a 800 KB executable (no optimisation, all debug info & symbols in, all checks in, strict bool eval etc, in short something which works as intended :D )

6. Yeah, cool, you're the best programmer, but where's the beef ? top previous next section

In fact, you understood that I built a small executable program for Win32 which does exactly what I wrote above as requirements ; nothing less, nothing more.
So let's see the results before I give you the link to that utility, called "MySMTPServer" ;-)

  1. do not relay SMTP ; if the domain is not one of ours (defined in MySMTPServer's configuration), we refuse the SMTP connection and that's all.
  2. allowing only a small subset of addresses for our domains to receive email from the exterior via SMTP
    If the domain isn't ours (SMTP relay case), or if the address is not one defined in MySMTPServer's configuration, we simply refuse the SMTP connection and that's all.
    26/02/2007 20:04:39 message de pour
    26/02/2007 20:04:39 refusé
  3. if the address is valid, try to repel spam - this saves our precious bandwidth and CPU use of the server -
    This I did by checking various headers of the email (received in memory only for the moment) : if it doesn't fulfill simple criteria, we trash the email
    26/02/2007 19:33:09 message de pour
    26/02/2007 19:33:09 accepté
    26/02/2007 19:33:10 Message good urinat from Lorinda Rowland <>
                        for Huang Natale <>
    26/02/2007 19:33:10 SMTP-DEBUG MsgId ok
    26/02/2007 19:33:10 SMTP-DEBUG Subject ok
    26/02/2007 19:33:10 SMTP-DEBUG desti KO huang natale/My Name
    26/02/2007 19:33:10 Message Refused.
    26/02/2007 18:58:16 message de pour
    26/02/2007 18:58:16 accepté
    26/02/2007 18:58:17 Message cheap oem soft shipping //orldwide 
                        from Anthony White <> for
    26/02/2007 18:58:17 SMTP-DEBUG MsgId ok
    26/02/2007 18:58:17 SMTP-DEBUG Subject KO
    26/02/2007 18:58:17 Message Refused.
  4. allow limited (secure) POP or IMAP access so that our current standard email client may get our emails in the standard way
    no modification is necessary on the email client ; all you've to do is add a "personality" (in Eudora speak) to go to your SMTP server's IP address via POP (I didn't implement IMAP)
    MySMTPServer, in turn, will only accept POP3 connections from a single IP address, which is the one YOU defined in the configuration.
  5. do this in a trusted inocuous way, for a minimal memory footprint, and for free if possible
    well, it's definitely free, I trust it (with the caveats below) because I run it :D and it has a very small footprint (7MB 4 MB now ; depends on the settings below) and doesn't crash which is not bad for a development done on Win32 using Microsoft's sockets implementation and after having had to hack through buggy components :D

    old versionMySMTPServer preview
    As you may see above, I'm lucky : in those 5 examples not a single spam email went stored in the maildrop (so no chance of ending in my POP mailbox :D)
    One was refused at the connection time for bad recipient, four for bad addressing, subject or compromised structure
    Of course, some pass through anyway, but I also have the standard spam filter on my email client and I can say that everyday, I must have between 1 and 3 spam emails being actually "received" by me (ie, seen and pushed to Junk mailbox without being displayed ;-)
Here's a sample configuration file:

this is MySMTPServer's config file - do not modify while running
@VGR 2007 - do not remove this line 
------------------ separator below is TAB ----------------------
yourself	First Lastname	alias
kw blacklist	7	OEM	viagra	moneyback	earning	money	casino	software	0EM
nb dom.<11	1
domain	2	webmaster	contact
rel.path.mbx	./mailbox/

The file is pure plain ol' text, the first column of each line explains what the line is about. Values are separated by the TAB character (ASCII#9). alias is a new (0.91 RC1) feature : you may add a secondary "accepted name"

7. Caveats, Disclaimer, TODO List top previous next section

Disclaimer : No warranty is offered of any kind. This is touchy software which works for me, but could very well crash your system for an unknown reason (the joy of Windows use ;-).
Caveat : I suspect a bug of some kind that affects some very few emails : they arrive with an empty body. I'm still searching what could be the cause.
TODO list by decreasing priority order : (due soon, ASAP in fact)

  1. make it a service
  2. implement the UIDL POP command if needed (probably not)
  3. using a database in stead of the filesystem ? (probably not)
  4. implement extended POP commands ? (probably not)
  5. make available for the rest of the world

8. Download Link top previous next section

MySMTPServer is available here in version 1.0 (ZIP, 245 KB ) 0.51 (ZIP, 380 KB ;-)
and here as a Win32 Service (version 1.1) (ZIP, 250 KB ) it's almost the same code, but you lose the visual window activity logging and the ability to turn SMTP receive off. You don't see the process in TaskManager, in the Task Bar nor in the SysTray (it's controllable in the SCM window)

Current Version and limitations (memory settings):
Update 09/03/2007 : the bug seems identified ; it's not a bug ; it's Indy being too strict on standards and choking on badly-coded attachments (theoretically, such an attachment has to have a size being an even number multiple of 4). More on this later.
Update 10/03/2007 : I will upgrade Indy to latest 9.0 or 10.0 - which implies probably a lot of problems and code upgrades to do - and in the meantime I stabilized a version 0.51 useable by you.
Update 31/03/2007 : The bug is fixed (I patched an Indy component). Current verion 0.90 RC1 is under test - coming out soon ;-)
Update 02/04/2007 : It seems ok, give me some days more of running time. Things are ***perfect*** for the time being.
Update 02/04/2007 : First official release 1.0
Update 03/04/2007 : Win32 Service version also available, version 1.1

Const globApp = 'MySMTPServer';
      cVer = '0.51 du 09/03/2007';'1.0 du 02/04/2007';

Const cMaxMsg = 100; // nbre maximal de messages de la maildrop à ressortir // max nbr msg out of the maildrop in one POP phase
      cMaxKW = 100; // nbre maximal de mots-clefs blacklistés ci-dessous // max number of blacklisted keywords (in subject)
      cMaxEmail = 20; // nbre maximal d'adresses e-mail pour un domaine // max nbr of email addresses per single domain name
      cMaxDomains = 1210; //nbre maximal de noms de domaine à gérer // max nbr of domain names

Those settings can be changed by simply recompiling. I chose values that I thought were reasonable for the time being.

9. Conclusion top previous section

Theoretically, now you should have a fully functional Windows Web + DNS + SMTP server, able to host as many domain names as you bought (nevertheless, evaluate the bandwidth consumption beforehand ;-)
Best regards,
Vincent Graux (VGR) for European Experts Exchange and Experts Round Table and Edaìn Works  back to list of articles
Last update 2021-03-15 16:05:35