The Funtoo Linux project has transitioned to "Hobby Mode" and this wiki is now read-only.
Funtoo:User Services/Simple Mail Server
How to set up a simple, secure, lightweight email server using Postfix to send emails without imap and pop or multiple domains
Managing your own email server doesn't have to be mystical and impenetrable; using a simple MTA like Postfix without any IMAP or POP configuration makes the task relatively easy. Regrettably, it is difficult to find good information on how to do this. What this guide will help you to do is to install an email server that is used only for sending, without any virtual domain or user base or even authentication, using only sending permission from a specific network of servers.
Prerequisites
If you intend to run your own mail server only for sending messages, you will need to have a DNS with at least one IP or hostname configured via TXT so that the SPF is verified by the receiving mail server, on a DNS server that can be viewed on the Internet in general. It is also essential for reliable email delivery to have a properly configured reverse DNS as many email servers will use reverse DNS and expect your IP address to resolve your advertised hostname.
Preparation
The following package need to be installed first, before we can do anything: mail-mta/postfix
root # emerge -avq mail-mta/postfix
Configuration
Now we come to the heart of the project. First we will have to configure Postfix modifying only two files: master.cf
and main.cf
Configuring DNS
create an entry of type A with the external IP of the mail server, for example:
mta.funtoo.org has address 192.150.253.194 mta.funtoo.org has IPv6 address 2001:470:4b:56:216:3eff:fefa:97b7
Setup reverse DNS, for example:
194.253.150.192.in-addr.arpa domain name pointer mta.funtoo.org.
Configure SPF using TXT entry, for example:
mta.funtoo.org descriptive text "v=spf1 a mx include:mta.funtoo.org ~all"
Configuring Postfix
Now we have to configure Postfix. Open your favorite text editor and uncomment the following lines at the top on /etc/postfix/main.cf
. We will be setting up the mail server's hostname and domain. How we fill this in depends on what your DNS and TXT records point to. If you have it set up so that your main domain is of the form tld.ext, then you will put that into the mydomain
field, otherwise, you will set it the same as the myshostname
field (in host.tld.ext form):
/etc/postfix/main.cf
- Postfix Configurationmyhostname = mta.funtoo.org
Finally, in this file, we have to enumerate the networks that can relay mail via our server. Generally we want to list only the subnets that we want to be able to send mail from (replace <LAN IP> with your LAN's subnet and <LAN netmask> with your LAN's netmask, and leave 127.0.0.0/8 in):
/etc/postfix/main.cf
- Postfix Configurationmynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 172.19.0.0/16
Next, we have to change some items in the same configuration file (we will be changing the defaults in the file to what is shown here). As this is a fresh install, the developers recommended that the compatibility level be set to 3.6:
/etc/postfix/main.cf
- More Postfix configurationcompatibility_level = 3.6
If we want Postfix to talk on port 25, we have to make sure the following lines are uncommented in the file /etc/postfix/master.cf
for smtp is inet
and { {c|ipass}}:
/etc/postfix/master.cf
- Postfix master service filesmtp unix n - y - - smtpd
smtp inet n - n - 1 postscreen
smtpd pass - - n - - smtpd
Final Steps
We want Postfix to appear when our server boots up, so we need to add it to the server boot; Once that's done, we'll start postfix with the command openrc
:
root # rc-update add postfix default root # openrc
Test you new e-mail server
test-mail.sh
- optional script for tests only#!/bin/bash
(
echo 'HELO GAT';sleep 1
echo 'MAIL FROM: <coffnix@mta.funtoo.org>';sleep 1
echo 'RCPT TO: <coffnix@gmail.com>';sleep 1
echo 'DATA';sleep 1
echo 'MIME-Version: 1.0';sleep 1
echo 'FROM: <coffnix@mta.funtoo.org>';
echo 'TO: <coffnix@gmail.com>';
echo 'SUBJECT: test';
echo 'Content-type: text/plain; charset=UTF-8; format=flowed';
echo ' ';
echo ' ';
echo 'Testing SMTP.';
echo '.';sleep 1
echo 'QUIT'; ) | nc -t mta.funtoo.org 25