added mailing functionality and -a option