Programming

Setting up a local mail server

By local mail server, I mean a mail server that just delivers mail from local users to local users. What? Why do I want to email myself? Well I don't want to email myself, but commands like cron, batch and at will send the output from the batch jobs to you in mail. I wanted to receive these logs so I needed a mail service on my linux box.

Mail software on windows usually involves a single application like Pegasus that does everything. Reading about unix mail reveals that this functionality (from a command-line point of view) is split into several components:

MTA (Mail Transfer Agent)
This is the program that recieves the mail and transfers it to the inbox of the recipient.
MDA (Mail Delivery Agent)
This (optional) component handles the messages and filters or re-routes them. You can conceivably configure several or none of these. Typical functions include auto-redirect or spam filtering.
MUA (Mail User Agent)
This is the program that allows you to read the emails and manage them.

I'm not that bothered by having a MDA, so I need to install an MTA & MUA! There are many options for both of these, and most of the arguments pro and con have been argued out on mailing lists for decades. I wanted simple and minimal, so I chose "postfix" and "mail" for my MTA and MUA respectivley. In the past I've used "sendmail" and "qmail" as MTA's and they both had their ups and downs.

Installing Postfix

This was real easy:

[ian@biggles scanner]$ su
Password:
[root@biggles scanner]# yum install postfix

YUM took a couple of minutes to download and install it. If you have a debian based distribution the command would be something like "apt-get install postfix"

Configuring Postfix

The config settings for Postfix are in /etc/postfix/main.cf . There are loads of pages that detail how to set up Postfix, but I found the basic config worked on Fedora 20 "out of the tin"

Installing Mail

The mail command is really basic; but it suits my needs. If you need something a little more user friendly there are clients like mutt and pine, and many GUI clients can be configured to read from your unix mailbox.

The only catch here is the package is called "mailx":

[root@biggles scanner]# yum install mailx

Testing it works

The obvious way to test is to submit a job:

[ian@biggles scanner]$ mail
No mail for ian
[ian@biggles scanner]$ batch
at> echo Yes
at> <EOT>
job 2 at Wed May 21 11:45:00 2014
[ian@biggles scanner]$
[ian@biggles scanner]$
[ian@biggles scanner]$ atq
[ian@biggles scanner]$ mail
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/ian": 1 message 1 new
>N  1 Ian Rolfe             Wed May 21 11:45  14/487   "Output from your job        2"
& 1
Message  1:
From ian@biggles.localdomain  Wed May 21 11:45:42 2014
Return-Path: <ian@biggles.localdomain>
X-Original-To: ian
Delivered-To: ian@biggles.localdomain
Subject: Output from your job        2
To: ian@biggles.localdomain
Date: Wed, 21 May 2014 11:45:42 +0100 (BST)
From: ian@biggles.localdomain (Ian Rolfe)
Status: R

Yes

& d
& q
[ian@biggles scanner]$ mail
No mail for ian
[ian@biggles scanner]$

Version 3 updated 21 May 2014, 12:39 p.m.