Super User is a question and answer site for computer enthusiasts and power users. 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

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

echo "Body of email" | mail -s "Subject"

If the emails are not being sent, does one need to specify the user name and password of a sending email address? All the mail tutorials I have read specify nothing about the sender address.

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? Thanks.

share|improve this question
up vote 9 down vote accepted

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.

share|improve this answer
Thanks for all the help. The pastebin command you suggested ended up meeting my needs. I will work on setting up a smarthost for mail relaying. – user001 Jan 31 '12 at 22:03

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.

share|improve this answer
@user001 Does this help? – Daniel Beck Jan 31 '12 at 20:57
@user001: In such cases, you might take a look at pastebins, some of which are easy to use from command-line. For example, curl -Fsprunge=\<- < myfile. – grawity Jan 31 '12 at 21:09
@user001: Do you have the exim4 daemon running? Does sudo mailq list the message? Have you checked the logs of the sending server (/var/log/exim4/mainlog) and the recipient (if possible)? – grawity Jan 31 '12 at 21:28
@user001: It could be that your ISP is blocking the connection. This is especially common on home connections - everything to port 25 simply gets dropped, in order to reduce the massive amounts of spam sent by infected PCs. (You still can configure relaying, though, which uses a different port and SMTP authentication.) – grawity Jan 31 '12 at 21:39
@user001: Relaying happens through another mail server (sometimes called a "smarthost"). Your network admins might help with this, if the academy has its own mail domain. If not, you could configure your server to send from your Gmail or similar mailbox; tutorials here. – grawity Jan 31 '12 at 21:59

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-auth=login
set smtp-auth-password=pass

In which case the email will be coming from "".

share|improve this answer
Thanks Karolos. Please see my edit. – user001 Jan 31 '12 at 20:53
@user001: Do you want just to be able to send mails (e.g. from scripts) or also to receive them ? – Karolos Jan 31 '12 at 20:56
Just to be able to send a message from a script. Thanks. – user001 Jan 31 '12 at 20:57
Note that this mailrc syntax is specific to heirloom-mailx. Some systems may come with GNU mailutils or BSD mailx, both of which would complain about syntax errors. (If that happens, I suggest installing heirloom-mailx - or even better, mutt or re-alpine.) – grawity Jan 31 '12 at 21:07
@grawity: thanks for mentioning this. – Karolos Jan 31 '12 at 21:12

Refer this How to send email from the Linux command line for some more information

share|improve this answer
Thanks SivaCharan. That is one of the tutorials I had already read, but it does not address my question about the from address. – user001 Jan 31 '12 at 20:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .