Mail command in a shell script

i wanted to write a shell script that can automatically read unread mails and copy each one into a different file. I was trying to use the MAIL command to do it, but this command requires user input inbetween, I was wondering how that could be achieved in a shell script.
Can sumone please suggest a way out. Thanks

any other command that can be used to achieve the same will also be welcome :slight_smile: .