How to dump/get mail list to a file on Linux

jl66
jl66 used Ask the Experts™
on
If I type mailx in console, it shows that

....
 U 17 J1.smith@A.com  Fri Mar 30 14:38  88/5740  "Re: Test1"
 U 18 J2.king@B.com  Fri Mar 30 16:50  56/3244  "Please read this one"
 U 19  J2.king@B.com Mon Apr  9 11:03 236/11783 "Server Failure"
....

Is there any way to dump all the lines above to a file? I do not need the email body, but need all the lines.
Do any gurus shed some light on it?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2013
Top Expert 2013

Commented:
Try

mailx -H > outputfile
Most Valuable Expert 2013
Top Expert 2013

Commented:
Did you read the above suggestion? Sorry, I've updated the comment, so you might not have received a message.
jl66Consultant

Author

Commented:
Thanks for offering the tip. Unfortunately, it did not work on my system. Have you tried it?
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Most Valuable Expert 2013
Top Expert 2013

Commented:
Yes.

mailx -H

lists all the headers in my mailbox.
Most Valuable Expert 2013
Top Expert 2013

Commented:
Well,

I'm running Unix (AIX).

In some other systems I found

mailx -P

working better than "mailx -H".
Most Valuable Expert 2013
Top Expert 2013
Commented:
... and in my oldest Linux (SuSE from 2004) I found I had to use

mailx -f < /dev/null

to get a header list without "mailx" going interactve at the end.
jl66Consultant

Author

Commented:
An equal question is that in mail box ie /var/spool/mail (a file), I expect it contains everything on mail. Which variable is for NEW emails and the emails that have been read?
Most Valuable Expert 2013
Top Expert 2013
Commented:
Emails which have been read using "mailx" go to ~/mbox (or the file pointed to by $MBOX) , unread mail stays in  /var/spool/mail/userid or the file pointed to by $MAIL.

mail -H -f ~/mbox lists the headers of mail which has been read.

Some mail readers (e.g. dtmail) add "Status: RO" to the header fields of mail which has been read, instead of moving it to ~/mbox.
jl66Consultant

Author

Commented:
Thanks for the update.
Unfortunately in our system, there is no -H option.
I tried to get something in the following way:

1) tail -f /var/spool/mail   #(mail box file).
2) send a mail to this linux server.
3) immediately a lot of messages shown on screen via tail -f.

The email software updates the file when any new email arrives. If I try mailx, it shows the mail I just sent >N ...., which is a new mail. I guess in the file /var/spool/mail there is some place to store this info ">N", or there is some other queue file to store it. How to find it?

Our system is redhat: 2.6.18-274.7.1.el5
Most Valuable Expert 2013
Top Expert 2013

Commented:
All files in the mailbox are "new", usually,

Files which are not "new" go to ~/mbox, as I already wrote above.
jl66Consultant

Author

Commented:
Very helpful. Close to what I wanted.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial