How do I set up the Unix 'mail' command?
I've had a look on Google and the man pages for mail, but I can't figure out how to set it up. All I want to do is set up my email address so that I can send email via the terminal. How do I do that?
Traditionally, Unix mail programs, including mail
, rely on a MTA (Mail Transfer Agent) to do the actual transmission.
You can use either a full-size MTA (postfix, exim4, opensmtpd) by configuring it with a 'smarthost' (relayhost), or a lightweight outgoing-only MTA (msmtp, ssmtp, esmtp, nullmailer) which always uses one.
For personal use, msmtp
will be easiest to set up – it can only send mail, not receive, and allows user-specific configuration.
Install msmtp
, then add your Gmail account into ~/.msmtprc
:
defaults tls on # the path below may need to be adjusted tls_trust_file /etc/ssl/certs/ca-certificates.crt account gmail from youraddress@gmail.com host smtp.gmail.com port 587 auth plain user youraddress@gmail.com account default : gmail
Now tell mail
to use msmtp
, by editing ~/.mailrc
:
set sendmail="/usr/bin/msmtp"
(If this does not work, run ln -s /usr/bin/msmtp /usr/sbin/sendmail
as root.)
Finally, if you want mail
/msmtp
to remember your Gmail password, it goes to ~/.netrc
:
machine smtp.gmail.com login youraddress@gmail.com password "your password here"
Unless your system admin has already set up the mail system, you must configure a Mail Transfer Agent. That is sendmail traditionally, modern systems use postfix or exim4.
http://www.postfix.org/
http://exim.org/