I would like to automatically save incoming emails to separate files. I am using mailx
to read emails. I understand I can manually save specific emails by entering the mailx command prompt and using the save
command (i.e. $ save email_number out_file
). I would like to automate this process if possible but the only way I know how to save emails is to enter the mailx prompt. I have other pyhthon scripts that will digest the saved emails. I realize that all incoming emails are essentially appended to one file /var/mail/mail_file
, and I can parse that file. However, it seems there may be a more elegant way to do this. I have looked over the mailx man page, and unless I'm missing it, I don't see directions to accomplish this. So,
Is there a way to automate saving mailx emails to different files? Possibly with a shell script or perl?
After a couple more days of searching around I have found a solution. Namely, procmail
. Nice instructions for using procmail can be found here: Mail Filtering with Procmail