Linux read root mail

What is the «You have new mail» message in Linux/UNIX?

Is this even actual «mail» in the same sense as email? Or is it just my system telling me something?

EDIT: In relation to this question, would I be able to send myself mail using the sendmail program like so: email@localhost ?

I have this one message in there that says «This text is part of the internal format of your mail folder. » so of course whenever I log in I am informed that I have mail.

In case anyone is looking, here is powerhshell one-liner to splits that into single files readable by outlook: $i=0;(gc .\mail\root -raw) -split ‘[^, ]From ‘|% <$i++;sc mail$i.eml -value ("From " + $_)>

7 Answers 7

Where is this mail?

It’s likely to be in the spool file: /var/mail/$USER or /var/spool/mail/$USER are the most common locations on Linux and BSD.

(Other locations are possible – check if $MAIL is set – but by default, the system only informs you about /var(/spool)/mail .)

Usually the spool file is in a very simple mbox format, so you can open it in a text editor or pager.

For a slightly more convenient way, most distributions come with a program called mail (or Mail , mailx ). You can try mutt or alpine ; you can even configure it to be sent to an outside mailbox. (See «is this real mail?» below.)

What does it contain, and who/what sent it?

Most often the messages contain output of cron jobs, or a system security report by logwatch, or similar junk. Read it and find out.

How important is it?

Depends greatly on the contents of each message.

You should at least scan the subject headers – often people ignore the mail for months never realizing that their daily cron jobs fail.

Is this even actual «mail» in the same sense as email? Or is it just my system telling me something?

Yes to both – it’s generated by your system telling you something, but it’s also actual email and can be handled as such.

You can (and should) configure your mail software – the «MTA» aka /usr/sbin/sendmail – to forward the messages to your personal mail address. The exact instructions vary depending on which MTA (if any) you have installed, whether this is a personal computer or a server, whether you have your own domain or use a @gmail.com, and so on.

Note that /usr/sbin/sendmail nowadays is a shared API and doesn’t necessarily mean the original Sendmail MTA. In fact, you shouldn’t use Sendmail, but something more modern like OpenSMTPD, Postfix, or Exim4. All of them provide the same /usr/sbin/sendmail tool, but they’re easier to configure, more secure, and just as powerful.

Good answer. Had you added links with information on how to configure OpenSMTPD, Postfix or Exim4 to forward mail to your normal email address it would have been even better.

Читайте также:  Установка java linux через терминал

I viewed my mail with cat /var/mail/$USER command and removed it with rm -rf /var/mail/$USER command.

@Andyc: Make the cronjobs not produce output. Use the appropriate «—quiet» or «silent» option of the program being run, or fix the job to not produce error messages by adding error checks where appropriate, or redirect the whole job’s output to /dev/null like in shell (cronjobs use shell syntax).

The easiest way for me was to run the following in a terminal:

Best practical answer so far that actually adds to the knowledge. Now I can read the mail. I wonder why it’s the bottom most answer.

I realize this is a pretty old question/answer, but this XKCD is relevant to the discussion. (hint: hover text)

For anyone wondering how to read these messages one by one, you can just use ‘mail’

Then type a message number from the list which you want to read.

To goto the next message you can type ‘next’, another useful command is ‘delete’..

To see more about how the mail program works, see the output of man mail .

Just to offer some clarification, it’s been the tradition for a long time for UNIX boxes to run a «locally configured» mailer daemon that doesn’t route messages through the Internet, but only copies messages to other users spool directories (as @John T mentioned). It is real SMTP-compliant email, it’s just not routed over the Internet because it doesn’t need to be.

So, if you fire up an email client (like alpine or mutt ) you can send mail to other users on the system by addressing to user@hostname , or in many cases, just specifying the user. You also likely have a command line utility called mailx that can be used to send a quick email using your shell.

Now, if you want to send messages to users on systems other than the one you are logged in to, that’s where the real fun begins. You’ll need to configure your mailer daemon to recognize and hand off external email to a transfer agent, configure the transfer agent, and do a whole bunch of stuff I don’t yet understand myself.

Источник

Read messages from “You have new mail in /var/mail/root”

When logging into your Ubuntu server, you might be greeted with the message You have new mail in /var/mail/root. But how do you read that mail and how did it get there?

It means that you have installed sendmail on Ubuntu (or any other flavour of Linux) and you received one or more messages in your inbox. The message(s) can originate from your system itself, or from an external e-mail address.

Read your messages in Ubuntu

To see what messages you received from the command line, this command will reveal the message(s):

The message could look like this:

From [email protected] Wed Jul 29 12:05:26 2015 Return-Path: [email protected]> Received: from hostname (localhost [127.0.0.1]) by hostname (8.14.4/8.14.4/Debian-4.1ubuntu1) with ESMTP id t6TG5QKu001540 for [email protected]>; Wed, 29 Jul 2015 12:05:26 -0400 Received: (from [email protected]) by hostname (8.14.4/8.14.4/Submit) id t6TG5QYK001533; Wed, 29 Jul 2015 12:05:26 -0400 Date: Wed, 29 Jul 2015 12:05:26 -0400 Message-Id: [email protected]> To: [email protected] From: [email protected] Auto-Submitted: auto-generated Subject: *** SECURITY information for hostname *** hostname: Jul 29 12:05:26 : root : unable to resolve host hostname

Removing messages from /var/mail/root

To purge these messages and to get rid of the message you received on logging in, you can simply delete it with this command:

Do not forget to include the > sign, otherwise it won’t work.

Read messages from “You have new mail in /var/mail/root” was last modified: July 29th, 2015 by Thomas

Читайте также:  Linux 2017 для новичков

Источник

Use Evolution to read local mailbox

How do you as a normal user, running a plain old Fedora Core desktop, read root’s local mail? It’s easier than you think.

Author: Kanwar Ranbir Sandhu
Date: April 14, 2005

When you install a Red Hat based GNU/Linux distribution, one of the packages installed by default is Sendmail. This is done so that system messages can be delivered to the root user. Some of the messages root receives includes messages like disk usage, remote login attempts, errors and so on aggregated by Logwatch. As alluded to here, Logwatch is a system log analyzer and reporter. Here’s an excerpt from the Logwatch man page:

LogWatch is a customizable, pluggable log-monitoring system. It will go through your logs for a given period of time and make a report in the areas that you wish with the detail that you wish. Easy to use - works right out of the package on almost all systems.

This is great: a program that can look through the logs YOU want, HOW you want, and then report the bits you’re interested in. The keyword here is «report». In order to do so, Logwatch mails the report to the root user, which is why Sendmail is installed by default, even on a desktop configuration. As long as you don’t turn off the Sendmail service or remove the package all together, Logwatch will do its daily run, and then send its report to root’s local mailbox in /var/spool/mail/root. A normal user cannot read root’s email, but you can configure your system to have any and all messages destined to root to be diverted to your local mailbox instead.

You’ll have to complete a two stage process in order to receive root’s email in your Evolution Inbox. Here’s what you do:

Stage 1

  1. Assuming you’re running X, start a GNOME Terminal. You can find this in the System Tools menu under Applications.
  2. Since you have to make changes to a system file, you’ll have to login as the root user. Type » $ su — «. Hit enter after typing the dash. You’ll be prompted to enter root’s password. Go ahead and type it in, then hit enter again. You’ll know you’re logged in as the root user by the change in the prompt from a «$» to a «#».
  3. At the moment Logwatch sends email to root’s local mailbox. We want to divert it to our local mailbox. To do that, we have to edit the file /etc/aliases. You can use any editor you want. For example: » «# vi /etc/aliases»
  4. You’ll now be looking at the file Sendmail uses to figure out which recepient to send email to for local users. You’ll notice that a default /etc/aliases file is setup to send all mail to the root user. Scroll down to the bottom of the file. You should now see a line similar to the following on your screen:
# Person who should get root's mail root:

Stage 2

Now that root’s email is aliased to your local mailbox, you need to configure Evolution to read the messages.

  1. Start Evolution.
  2. Go to Tools -> Settings.
  3. Click Mail Accounts.
  4. Click Add.
  5. Click Forward.
  6. Type in a name in the «Full Name» field.
  7. For the Email Address field, type in your login ID followed by @localhost. For example:

You’re done! You’ll notice in the Mail Account window that the Protocol listed for your new mail account is «mbox». This indicates that Evolution will be managing your local mailbox. Now when your system sends messages to the root user, Sendmail will use the alias you defined in /etc/aliases to deliver the mail to your local mailbox. Your Logwatch reports should now be picked up by Evolution for you to review. You can of course use any mail application to do this, so try Stage 2 with another client, such as Thunderbird.

man pages

I hope that was helpful. If you want to learn more about some of the applications mentioned in this How To, read the following man pages:

Thank you Kanwar!
This page was generously written and donated to the community by Kanwar Ranbir Sandhu.
* Content Last Updated 2005-04-14 by Kanwar Ranbir Sandhu
* Minor Grammer Last Updated 2008-02-24 by Dotan Cohen
* HTML Last Updated 2008-02-24 by Dotan Cohen

All contents copyright ©1998-2018 DotanCohen.com. All rights reserved and protected.
This website is not compatible with MS Internet Explorer. Please upgrade to Chrome, Firefox, or Opera for optimal experience.
About This Site

Use Evolution to read local mailbox Use Evolution to read local mailbox Use Evolution to read local mailbox
[email protected] [email protected] [email protected] [email protected] [email protected]

Источник

“You have mail” – How to Read Mail in Linux Command Line

How to read the you have mail message in Linux Ubuntu

This message indicates that there is a message in your spool file. Usually the spool file is in a very simple mbox format, so you can open it in a text viewer like less or with the mail program. In most cases, this is not a message from a long lost lover, but instead a system message generated by your Linux mail service. (sad)

View Spool File

Use the following command to read the mail for the currently logged in user. The $(whoami) variable returns the currently logged in user.

You can use the ↑ and ↓ arrows on your keyboard to scroll through the spool file.

Press uppercase G to scroll to the bottom of the file and lowercase q to quit.

If you wish to read another user’s mail, just enter their user name.

Delete Spool File

You can simply delete the /var/mail/username file to delete all emails for a specific user. The $(whoami) variable returns the currently logged in user.

Using the mail Program

You can also use the mail program to easily list and view messages in your spool file. If mail is not installed, you can install it with sudo apt install mailutils .

Messages will be listed with a corresponding number:
mail "/var/mail/john": 6 messages 6 new >N 1 Mail Delivery Syst Thu Feb 15 21:12 80/2987 Undelivered Mail Returned to Sender N 2 Mail Delivery Syst Fri Feb 16 00:09 71/2266 Undelivered Mail Returned to Sender N 3 Mail Delivery Syst Fri Feb 16 00:16 71/2266 Undelivered Mail Returned to Sender N 4 Mail Delivery Syst Fri Feb 16 00:21 71/2266 Undelivered Mail Returned to Sender N 5 Mail Delivery Syst Fri Feb 16 00:22 71/2266 Undelivered Mail Returned to Sender N 6 Mail Delivery Syst Fri Feb 16 00:24 75/2668 Undelivered Mail Returned to Sender ?

After the ? prompt, enter the number of the mail you want to read and press ENTER .

Press ENTER to scroll through the message line by line and press q and ENTER to return to the message list.

To exit mail , type q at the ? prompt and then press ENTER .

Delete All Messages using mail

To delete all messages using mail, after the ? prompt, type d * and press ENTER .

Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.

p.s. I increased my AdSense revenue by 200% using AI 🤖. Read my Ezoic review to find out how.

Источник

Оцените статью
Adblock
detector