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
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.
msmtp, then add your Gmail account into
defaults tls on # the path below may need to be adjusted tls_trust_file /etc/ssl/certs/ca-certificates.crt account gmail from email@example.com host smtp.gmail.com port 587 auth plain user firstname.lastname@example.org account default : gmail
msmtp, by editing
(If this does not work, run
ln -s /usr/bin/msmtp /usr/sbin/sendmail as root.)
Finally, if you want
msmtp to remember your Gmail password, it goes to
machine smtp.gmail.com login email@example.com password "your password here"
On many systems you will find a
mailx command which can be used to send email. This may be a link to the mail command, but changes the behavior of the command. As other have noted, this assumes you have a MTA (Mail Transfer Agent) configured on your server. It can be used interactively using a command like:
mailx -s "This is a message" firstname.lastname@example.org This is a message .
Or with a pipe to send the output of a command:
cat myfile.txt | mailx -s "This is the file" email@example.com
Running it as
mailx -h should give you usage instructions.
If you're not bound to the
nail offers a similar interface but can send mail using SMTP.