Does one need to set up a mail server before being able to use the linux mail
command?
Does the mail command require a mail server
mail-command
mail-command
Does one need to set up a mail server before being able to use the linux mail
command?
Best Answer
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.Example
You can use the
dig
command to see this: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:
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 thedig
command you'll notice theSERVER: ...
line at the bottom. That's the DNS server servicing your request.Example
My
/etc/resolv.conf
file contains the following:And queries such as this one, using
dig
:Result in this at the bottom:
And for the astute reader, one my ask, how is this configured? The answer is the
/etc/nsswitch.conf
file. Specifically this line:That says, use files first (
/etc/hosts
), followed bymdns4_minimal
. That's a multicast DNS. It's basically a cache of previous look ups. Lastly it usesdns
which is the IP address of thenameserver
designated in the/etc/resolv.conf
file.