Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I'm still kind of new to linux, but what are the steps towards setting a linux box up in such a way that it can send mail using shell?

echo "hello world" | mail johnny@moo.com

I mean, I've done the necessary sudo apt-get install mailsystem (or something like that) which sets up the mail command. However, will you also have to set up a .com to point to your linux box as its SMTP server? What else needs to be done?

share|improve this question

I'm assuming that you are using a Debian based derivative given that you mentioned apt-get in your question.

This can be done fairly simply using the exim4 mail package. A simple

apt-get install exim4 exim4-config

Will install everything that you need to send mail via smtp. Note you need to be root or use sudo for the apt-get command to work.

During the install the exim4-config package setup will ask you a number of questions that will let you configure things appropriately.

You should probably select the mail sent by smarthost; no local mail option and give it details of your outgoing mail provider. It is also possible to send mail directly as an internet site; mail is sent and received directly using SMTP but that can have issues with your internet providers so you are best to start off using a smarthost.

If you need to tweak your configuration you can use

dpkg-reconfigure -plow exim4-config

I'm guessing that your outgoing mail provider will require your machine to authenticate before it allows sending of mail. In that case you need to add an entry into /etc/exim4/passwd.client . The format is quite simple each takes the format of servername:login:password and is documented in

man exim4_files

The latter also tells you how to configure other settings files. It will likely be of interest to setup /etc/email-addresses to ensure that when you send email as a specific user it gets sent via your ISP as your real outgoing address

share|improve this answer
Unless you have a static address configure your system to use a Smarthost. Usually your ISP will have an SMTP server intended for such use. – BillThor Feb 23 '11 at 17:01

I don't know what debian uses as /usr/bin/mail, but try to get a mail client that can show you the SMTP dialog that it goes through. I had "nail" (apparently now "mailx" - http://heirloom.sourceforge.net/mailx.html) on one of my linux boxes:

11:46AM 5 % nail -v -s "test letter" me@somewhere.com 
blah blah blah
me@somewhere.com... Connecting to [] via relay...
220 mydomain.com ESMTP Sendmail 8.13.8/8.13.3; Wed, 23 Feb 2011 11:46:38 -0700
>>> EHLO localhost.intranet
250-mydomain.com Hello localhost [], pleased to meet you
250 HELP
>>> MAIL From:<me@mymachine.intranet> SIZE=230 AUTH=me@mymachine.intranet
250 2.1.0 <me@mymachine.intranet>... Sender ok
>>> RCPT To:<me@somewhere.com>
>>> DATA
250 2.1.5 <me@somewhere.com>... Recipient ok
354 Enter mail, end with "." on a line by itself
>>> .
250 2.0.0 p1NIkcHH024098 Message accepted for delivery
me@somewhere.com... Sent (p1NIkcHH024098 Message accepted for delivery)
Closing connection to []
>>> QUIT
221 2.0.0 mydomain.com closing connection

The "-v" flag to nail (mailx) cause it to show you the SMTP dialog. That output can be invaluable when troubleshooting.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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