An MTA skeleton in C

If you really, really want to use C, I have provided an initial skeleton directory to get you started. It is available at mta.tgz in the machprobs directory. The tarball contains four files: domain.c, domain.h, Makefile, and mta.C. You'll find the first two files useful for looking up the destination MTA for messages you're trying to deliver (see the following section on mail exchangers). The Makefile, as the name implies, is a GNU makefile that builds the executable. (If you are trying to build on Linux, you should follow the directions in the comments about how to edit the Makefile.)

The last file, mta.C, could be used as the basis for an MTA. Currently, it just accepts TCP connections, closes them, and waits for another. You can run the executable by typing:

% ./mta 2225
where 2225 is the port you want it to listen on. In order not to conflict with the already running MTA (sendmail), you should run your MTA on a port other than 25 (larger than 1024). The file domain.c handles the difficult parts of MX processing. getmxrr() will return an ordered list of machines that you can try to deliver mail to for a given domain. mta.C includes some sample code showing you how to use it.

Last modified: Sun Feb 10 08:03:33 EST 2008