How can i send /var/mail/root again?

6,299

Solution 1

formail, part of procmail (and probably already available on your system) can take a mailbox, split it up into messages, and then run a command on each one. From the man page:

   -s   The input will be split up into separate mail messages, and  piped
        into  a  program  one  by  one (a new program is started for every
        part).  -s has to be the last option specified, the first argument
        following  it  is  expected to be the name of a program, any other
        arguments will be passed along to it.  If you  omit  the  program,
        then  formail  will  simply  concatenate the split mails on stdout
        again.  See FILENO.

So you can do what I think you want like this:

  formail -s /usr/sbin/sendmail -oi -t < /var/mail/root

Solution 2

mutt -f /var/mail/www-data

Then within mutt...

T.*
;b

T puts it into tagging mode, and .* tags all messages. The semi-colon applies the next command to all tagged messages, and finally b "bounces" the messages to an address it will prompt for.

From memory, I think either

D.*

or

T.*
;d

Will then empty the mailbox.

Share:
6,299
Max
Author by

Max

Updated on September 17, 2022

Comments

  • Max
    Max almost 2 years

    Through some misconfiguration I've a lot of emails in /var/mail/root and /var/mail/www-data

    How can I "loop" over these files and send each mail another time?

  • user2751502
    user2751502 over 14 years
    But also what kriss said re: addressing; this solution assumes that you've fixed your local aliases or something to send the messages somewhere other than back into /var/mail/root. You could, for example, do "formail -s /usr/sbin/sendmail -oi [email protected]" to redirect all the messages.
  • gokva
    gokva over 12 years
    assuming that www-data and root are now properly configured, something like "for foo in ls /var/mail; do formail -s /usr/sbin/sendmail -oi $foo < ./$foo ; done" should loop each file and locally deliver..