I am curious how system daemons on a local Linux host send email.

  • Is there some type of email framework already built in?
  • Do I need a MTA or a MUA?
  • What part does "Sendmail" play and is it a requirement?
  • How would I configure the server to be able to send via another host?
  • How does the “mail” command fit into this?
  • How does /home/user/maildir fit into the picture?
  • 1
    That's a lot of questions. :-) I think you need to break it down a bit. May 7, 2013 at 17:41
  • Yes, but I am looking for a general overview of how email is handled
    – Corey
    May 7, 2013 at 18:19
  • Um, read a book? :-) May 7, 2013 at 18:20
  • As I understand it, canonical and reference questions are encouraged in the stack exchange system. I have Googled it a bit, and haven’t found a great resource to answer my questions. If you know of an article or book, please do tell.
    – Corey
    May 7, 2013 at 18:38
  • Ch 2 of http://www.amazon.com/Exim-SMTP-Mail-Server-Official/dp/0954452976 seems to have a reasonable coverage of Internet Mail. The chapter is "How Internet mail works". It probably would not answer everything in your question, though. May 7, 2013 at 19:07

3 Answers 3


You've asked a pretty broad question—explaining all of it in detail would take many pages. In brief:

There are several programs involved in sending mail on a Linux/Unix machine. There are many to choose from for each role:

  • Mail User Agent (MUA). This is what you read and compose mail with. It's the user interface to the system. Examples: mutt, Thunderbird, Evolution, kmail, ...
  • Mail Delivery Agent (MDA). This handles putting mail into local mailboxes. Also can handle filters, etc. Examples: procmail, maildrop.
  • Mail Transfer Agent (MTA). This handles sending and receiving email between systems, usually over the Internet with SMTP. Examples include exim, postfix, qmail, sendmail etc.

Often, the MTA and MDA are combined. E.g., exim does both (though it can run with a separate MDA as well). And some MUAs (e.g., Thunderbird) handle all three (though with very limited MTA functionality).

Now, there are two interfaces used to send mail:

  1. Make an SMTP connection to localhost:25, and speak SMTP to send a message.
  2. Invoke /usr/sbin/sendmail, and pipe a message to it. (Or speak SMTP over the pipe, and there are a bunch of arguments, check the manpage if interested).

(2) is pretty common. Note that this is the native interface to the sendmail MTA, but pretty much every other Unix MTA emulates the interface—its more or less the standard way to send mail on a Unix box.

So, when you run mail [email protected] and type in a message, mail invokes /usr/sbin/sendmail to pass that message to the system MTA. The system MTA then uses its local configuration to determine what to do with the message:

  • Mail is to the local mailname/hostname, so do a local delivery (pass to the MDA)
  • Make a DNS request for the MX records, do a remote SMTP delivery
  • Custom action configured for this domain/email address/whatever. MTAs are usually very flexible.

How does /var/spool/mail/user or ~/Maildir fit into this? That's just where the MDA has been configured (or defaults) to put mail it delivers.

So, for your RAID monitoring, you probably want an MTA installed. If you're emailing it to your gmail account or whatever, you don't need an MDA.

The easiest setup would be if you have an ISP which provides an outgoing SMTP relay (a.k.a. smarthost; most do). Then you just need to set up a MTA that sends all mail there. Ubuntu has email setup documentation which mentions that Exim should already be installed, but you need to configure it to get mail off your system (which is fairly easy). See also "Lightweight outgoing SMTP server" here on Unix.SE.

  • does using /usr/sbin/sendmail require sendmail to be installed? what if I choose postfix or exim? Also, how can I have messages sent to my gmail account instead of the local root account?
    – Corey
    May 7, 2013 at 18:31
  • 1
    @Corey "but pretty much every other Unix MTA emulates the interface"—that includes postfix and exim (so, no, it doesn't require sendmail to be installed). The easiest way to have them go to gmail is to edit /etc/aliases and put root: user@gmail in there. With exim, that's all you do, with others, you may need to run a command like makealiases
    – derobert
    May 7, 2013 at 18:35
  • Thanks!, I missed the "emulates the interface" part the first time through.
    – Corey
    May 7, 2013 at 18:45
  • In general, I think it is better to use a proper MTA and pass everything to it, rather than try to send email directly from a MUA like Alpine or Thunderbird. For example, if there is a problem with the connection, the email gets lost (though you might have a copy in sent mail). Also, debugging sending mail problems is much easier with a MTA. May 7, 2013 at 19:38
  • @FaheemMitha Thunderbird, at least, should keep the unsent mail and let you know there was a problem (either in an outbox, or with an error when you hit send, leaving the compose window open). Of course, the MUA is only sending to a smarthost, not doing DNS lookups, etc. to deliver mail to random hosts on the 'net.
    – derobert
    May 7, 2013 at 19:59

Is there some type of email framework already built in?

Yes. There are multiple options for most distros. You can use MTA's such as Postfix and Sendmail on most of the larger distros such as Debian, Ubuntu, Fedora, CentOS, etc. It really comes down to what your preference is.

Do I need a MTA or a MUA?

Depends. Most of the Linux distros do come with an MTA and it's typically so that system generated emails can be delivered from various crons and daemons that are running on the system. In these cases the MTA is usually configured to only deliver the email locally to root or an admin type of account on the system.

As far as MUAs, there are a huge variety of choices for these. They range from terminal based apps such as mail and mutt up to Evolution and Thunderbird.

How would I configure the server to be able to send via another host? I’m not concerned with mail between local users on the box (There are only 2 so far, my account and root.), but I’m curious how that works as well.

If you're using a MTA such as Sendmail you can typically configure the box to be a smart forwarding host so that it just blindly forwards any mail that it can't deliver locally to root or an admin account on to some designated host that will take care of delivering mail originating from the host.

How does the “mail” command fit into this?

This is just a MUA.

How does /home/user/maildir fit into the picture?

Only the accounts that are local to the host and that have received mail will typically have email dropped into this directory. The mail showing up here is usually being delivered by the locally configured MTA.

Is this something inherited from Unix?

Not sure how to address this question.

If you're asking about the apparent difference between say a PC that typically doesn't include MTA/MUA types of applications on the box and a Unix box that typically does.

Then I would say the following:

It's more to do with the types of applications that Unix boxes would fill vs. those of a PC. It was generally the norm that most Unix boxes were used as servers, and servers need to deliver mail from a variety of daemons and services that run on them. These services typically didn't have a user account associated with them, so a MTA was required to get system emails out of the box to the rest of the world.

But IMO, I find it unusual that a PC doesn't include these types of functionality, but that's just me 8-).


None whatsoever... all the mail related packages/functionality can be left out. All distributions I know offer a variety of MTAs, MUAs, handlers for mail stores (POP, IMAP servers), spam filters/measures, ...

  • 1
    Actually, I think the system does expect mail to be running locally for system admin type stuff. May 7, 2013 at 17:40
  • cron requires it to send mail
    – jordanm
    May 7, 2013 at 18:10

Not the answer you're looking for? Browse other questions tagged .