How is mail actually sent when I use the Linux "mail" command?

Solution 1:

What email account is used to send an email when using the mail command from the linux terminal as in:

In default configurations, it's the very same account you used to log in. Your computer has a mail server program (a MTA) installed; usually either Postfix or Exim4, sometimes Sendmail or qmail.

The email address of this account is your-login@hostname or your-login@fqdn, where the FQDN can be obtained from hostname -f. However, right now you cannot receive mail to this account, since the MTA is configured for "local mail only" (as the error message below says) and will not accept messages from outside.

Edit: So if I receive an error message to the effect of "Mailing to remote domains not supported", does this mean my ISP has blocked sending emails? Is there any way around this?

No; this error message is returned by your own computer. The mail server is configured to only transfer local mail – from one user to another (most commonly, from the cron daemon if a cronjob fails). Usually these messages go to /var/mail/login and are readable using mail, mutt, re-alpine, or similar programs. (IIRC, Thunderbird had the ability to import local mail spools as well.)

It is not hard to reconfigure the mail server to send and receive mail to/from other sites; depending on the MTA installed and on the Linux distribution, even a single command might be enough: for example, dpkg-reconfigure postfix if the system is Debian with Postfix.

However, I'm guessing you are using this on a personal computer, so it would be better to use an external mail account instead – for example, your Gmail address if you have one. Find out which MTA is installed (on Ubuntu/Debian, dpkg -S /usr/sbin/sendmail will tell you), then google for "program-name relay gmail" for a tutorial.

Alternatively, install a MTA specifically designed for relaying; msmtp and esmtp are good choices and easy to configure.

Solution 2:

The mail command sends mails under the current account, i.e. username@domain ; however, usually internet service providers prevent users from running their own mail servers (by blocking the relevant ports) to avoid spam, and therefore your email is not sent.

But the sending problem could also be related to the configuration of your machine.

Edit: enabling mail to send emails from e.g. gmail. Put the following information into your ~/.mailrc file, which provides basing configuration to mail. However, make sure that this file is only accessible to you (using chmod 600 ~/.mailrc)

account gmail {
set smtp-use-starttls
set ssl-verify=ignore
set smtp=smtp.gmail.com:587
#set smtp-auth=login
set [email protected]
set smtp-auth-password=pass
set [email protected]
}

In which case the email will be coming from "[email protected]".

Solution 3:

It's the account name and host name of the sending user, for example root@myserver. It's not necessarily an actual mailbox that can receive email from the outside.