3

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?
Corey
  • 555
  • 3
  • 6
  • 15
  • 1
    That's a lot of questions. :-) I think you need to break it down a bit. – Faheem Mitha May 07 '13 at 17:41
  • Yes, but I am looking for a general overview of how email is handled – Corey May 07 '13 at 18:19
  • Um, read a book? :-) – Faheem Mitha May 07 '13 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 07 '13 at 18:38
  • Ch 2 of [http://www.amazon.com/Exim-SMTP-Mail-Server-Official/dp/0954452976](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. – Faheem Mitha May 07 '13 at 19:07
  • "Is this something inherited from Unix?" is ambiguous. – Faheem Mitha May 07 '13 at 19:43
  • I'm familiar with email in general; smtp, pop3, imap, mx records, etc. The email framework within a local linux box is what I'm a little fuzzy about. – Corey May 08 '13 at 03:49
  • Ok, but please clarify/elaborate on the "inherited from Unix" thing. I'm still unclear what it means. – Faheem Mitha May 08 '13 at 08:12
  • I was just curios if Unix had similar features. I will that from the questions as it’s not really important. – Corey May 08 '13 at 16:00
  • I don’t really understand why this was closed. It seems like a pretty standard reference question about how email works and is configured at the individual host level. – Corey May 08 '13 at 16:01
  • I can tell you why I voted to close it. Even though I answered your questions, this type of question isn't a good fit per the [FAQ](http://unix.stackexchange.com/faq). For one thing, it's asking too many questions in a single question. Another reason is that, the questions you're asking don't really have a black or white answer to them. They're completely open ended types of question which could lead to discussion and debate, which is never really allowed on SE sites. But I did answer you so hopefully you're questions have been somewhat answered. – slm May 08 '13 at 16:27
  • I disagree with the closing of this question. While I was a bit doubtful about the question initially (and I think it could be written more clearly), I think such overview questions are legitimate - they could be considered reference questions and could reasonably be community wiki. Also, the question has two good detailed answers. I've voted to reopen. I encourage others to do the same. Currently there are three reopen votes, and two more are needed – Faheem Mitha May 09 '13 at 17:49
  • How much rep is needed to vote for re-open? – Corey May 09 '13 at 22:26
  • @Corey: From the [unix.sx FAQ](http://unix.stackexchange.com/faq#reputation), `3000 Vote to close, reopen, or migrate any questions`. – Faheem Mitha May 11 '13 at 01:52

3 Answers3

7

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.

derobert
  • 107,579
  • 20
  • 231
  • 279
  • 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 07 '13 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 07 '13 at 18:35
  • Thanks!, I missed the "emulates the interface" part the first time through. – Corey May 07 '13 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. – Faheem Mitha May 07 '13 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 07 '13 at 19:59
  • @derobert I edited the question to be more generic and reference like – Corey May 09 '13 at 22:25
  • @Corey I'm already one of the reopen votes. You could try stopping by the chat room http://chat.stackexchange.com/rooms/26/unix-and-linux and seeing if you can drum up two more reopen votes... – derobert May 10 '13 at 14:55
2

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-).

slm
  • 363,520
  • 117
  • 767
  • 871
0

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, ...

vonbrand
  • 18,156
  • 2
  • 37
  • 59