Does one need to set up a mail server before being able to use the linux mail command?

  • possible duplicate of Can I set up system mail to use an external SMTP server?
    – slm
    Oct 3, 2013 at 21:19
  • @slm not really the same as that question hints that one needs an SMTP server to run mail, but I'm asking whether it is absolutely necessary
    – puk
    Oct 3, 2013 at 21:23
  • 1
    Yeah it's a possible duplicate, I've answered you b/c that Q takes it a bit too specific. Still feels like a dup but I answered you anyway 8-)
    – slm
    Oct 3, 2013 at 21:31

2 Answers 2


No you do not require a mail server to send mail. I'm most familiar with Sendmail and there are 3 classifications of functionality that fulfill email as a service. MDA (Mail Delivery Agents) is 1, and MTA (Mail Transfer Agents) is 2, and 3 is MUA (Mail User Agents).

The terminology get's confusing but you do not require an MTA to be running all the time. The MTA will be called each time the MUA (mail) wants to "send" mail.

When you run mail and you specify an address to send mail to, sam@example.com. The mail client will summon the MTA (/usr/bin/sendmail) which will then query DNS for that host/domain (example.com), and find out what value is designated for its MX record. MX stands for Mail Exchanger.


You can use the dig command to see this:

$ dig gnu.org mx

; <<>> DiG 9.7.4-P1-RedHat-9.7.4-2.P1.fc14 <<>> gnu.org mx
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 21053
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 2

;gnu.org.           IN  MX

gnu.org.        299 IN  MX  10 eggs.gnu.org.

eggs.gnu.org.       299 IN  A
eggs.gnu.org.       299 IN  AAAA    2001:4830:134:3::10

;; Query time: 218 msec
;; WHEN: Thu Oct  3 17:27:22 2013
;; MSG SIZE  rcvd: 90

So the client will attempt to connect to eggs.gnu.org on port 25 to deliver this email.

DNS server?

@puk asked the following follow-up question:

Is this DNS on my local machine?

To which I replied:

@puk - it can be in the same manner that the mail server can be, but typically it's not. Look in your /etc/resolv.conf file and also when you run the dig command you'll notice the SERVER: ... line at the bottom. That's the DNS server servicing your request.


My /etc/resolv.conf file contains the following:


And queries such as this one, using dig:

$ dig gnu.org mx

Result in this at the bottom:

;; Query time: 259 msec
;; WHEN: Thu Oct  3 17:46:13 2013
;; MSG SIZE  rcvd: 90

And for the astute reader, one my ask, how is this configured? The answer is the /etc/nsswitch.conf file. Specifically this line:

hosts:      files mdns4_minimal [NOTFOUND=return] dns

That says, use files first (/etc/hosts), followed by mdns4_minimal. That's a multicast DNS. It's basically a cache of previous look ups. Lastly it uses dns which is the IP address of the nameserver designated in the /etc/resolv.conf file.

  • Is this DNS on my local machine?
    – puk
    Oct 3, 2013 at 21:40
  • @puk - see updates.
    – slm
    Oct 3, 2013 at 21:44
  • @puk - I've added more....
    – slm
    Oct 3, 2013 at 21:50

It really depends on which version of mail you are using.

All versions need an MTA to actually deliver the mail, but some versions are capable of using SMTP to talk to a remote MTA (the "smarthost", e.g. your ISP's mail server) and some can only pipe the message to /usr/sbin/sendmail to send the mail via a local MTA.

In the latter case, the local MTA could be a full-fledged MTA like sendmail or exim or postfix. Or it could be a simple send-only MTA like nullmailer or ssmtp. Or a slightly more sophisticated mini-MTA like msmtp that also supports queuing mail for later delivery.

In the Free Software & Open Source world, there are two main variants of the mailx package (which provides the mail command): bsd-mailx and heirloom-mailx.

bsd-mailx does not speak SMTP and can only send mail by piping it to /usr/sbin/sendmail

hierloom-mailx can speak SMTP to a smarthost as well as the traditional 'pipe-to-sendmail' method.

So, to answer your question "Do you need a mail server?". Yes, sort of. You need one but, depending on which version of mail you have installed, you may not have to install and configure it on your own system.

IMO, you are better off with a minimal MTA like msmtp than relying solely on a smarthost with heirloom-mailx because you still need to queue mail for later delivery when your internet connection is down or your smarthost is unreachable. With a local queue, mail and crond and other programs can just send-and-forget any mail. Without a local queue, they have to deal somehow with the error condition if the smarthost is unavailable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.