Funtoo:User Services/Simple Mail Server

From Funtoo
< Funtoo:User Services
Revision as of 01:04, July 29, 2022 by Coffnix (talk | contribs) (Created page with "= 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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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.


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.


The following package need to be installed first, before we can do anything: mail-mta/postfix

root # emerge -avq mail-mta/postfix


Now we come to the heart of the project. First we will have to configure Postfix modifying only two files: and

Configuring DNS

create an entry of type A with the external IP of the mail server, for example: has address has IPv6 address 2001:470:4b:56:216:3eff:fefa:97b7

Setup reverse DNS, for example: domain name pointer

Configure SPF using TXT entry, for example: descriptive text "v=spf1 a mx ~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/ 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/ - Postfix Configuration
myhostname =

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 in):

   /etc/postfix/ - Postfix Configuration
mynetworks = [::ffff:]/104 [::1]/128

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/ - More Postfix configuration
compatibility_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/ for smtp is inet and { {c|ipass}}:

   /etc/postfix/ - Postfix master service file
smtp      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 - optional script for tests only
echo 'HELO GAT';sleep 1
echo 'MAIL FROM: <>';sleep 1
echo 'RCPT TO: <>';sleep 1
echo 'DATA';sleep 1
echo 'MIME-Version: 1.0';sleep 1
echo 'FROM: <>';
echo 'TO: <>';
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 25