How does the mail command work

emailmail-command

I am curious as to how the mail command works. My computer has postfix server installed by default with red hat and is connected to a network that includes a mail server. I had assumed that when I tried to send an email with the mail command it would fail and bounce the email back to me with a message like "Can't deliver to 'foo@example.com'" since the postfix mail server was never set up by me.

However, to my surprise when I sent the email to foo@example.com with the mail command, I received the email correctly and was told it came from root@localhost. I am therefore wondering how this email was able to be sent without an email server. How could whichever server managed this know how to correctly deliver the mail with the correct protocols and such to the email address that was given?

Best Answer

My computer has postfix server installed by default with red hat

That's basically your answer right there: RedHat included a default configuration with Postfix, sufficient for it to deliver mail.

How to route email is published in DNS (it doesn't just turn host names into IP addresses); most likely your machine's Postfix asked DNS where to deliver mail for example.com (i.e., the MX records for example.com.). DNS gave it a list of mail servers that accept example.com email, and Postfix made an SMTP connection to one of them and handed off the email.

[The full technical details of this are beyond the reasonable scope of a single Unix.SE answer, but hopefully that's a broad overview that'll guide your research if you wish to learn more.]

Related Question